ken_nogi/develop2/テスト用サイトテーブル/script/02_script.js
Kenichiro NOGI 7b357fa2cf 2025-11-08
2025-11-08 10:26:52 +09:00

79 lines
1.5 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
なにをするか?
1)変数の定義
2)関数の定義 引数 戻り値
3)関数の中身の処理の定義
制御構文の活用
4)関数の実行
5)結果の出力
*/
// 1)変数の定義
const greeting = "Hello, World!";
let str = "Hello, JavaScript!";
// 変数の定義の範囲
// ブロックスコープ({}の中)
// const と let の違い[
// const: 再代入不可、let: 再代入可能
//greeting = "Hello, Everyone!"; // エラーになる
str = "Hello, Programming!"; // 問題なく再代入できる
// 関数とは? 特定の処理をまとめたもの
//引数とは 関数に値を渡すためのもの
console.log("Hello from script 02_script.js");
function messageHyouji(message) {
console.log(message);
return;
}
//一般的な構文 if for while switch dowhile など
// if for while switch dowhile
// 3)関数の中身の処理の定義
messageHyouji(greeting); // 4)関数の実行
//インクリメント デクリメント
// i = i + 1;
// i += 1;
// i++;
function kurikaeshiHyouji() {
let i;
for (i = 1; i <= 10; i++) {
console.log(i);
}
console.log("終了しました");
}
kurikaeshiHyouji();
function tasashiteHyouji() {
let sum = 0;
for (let i = 1; i <= 10; i++) {
sum += i;
console.log(`現在の合計: ${sum}`);
}
console.log(`1から10までの合計は: ${sum}`);
}
tasashiteHyouji();
//var message = "Hello, Universe!";