From d1a9a1e54a8567af4513b55970ab293489b35d23 Mon Sep 17 00:00:00 2001 From: Fridge0 Date: Tue, 26 Sep 2023 14:22:51 +0900 Subject: [PATCH 01/11] =?UTF-8?q?=E8=A4=87=E5=90=88=E6=BC=94=E7=AE=97?= =?UTF-8?q?=E5=AD=90=E3=81=AE=E7=A7=BB=E5=8B=95=E3=80=81=E3=82=A4=E3=83=B3?= =?UTF-8?q?=E3=82=AF=E3=83=AA=E3=83=A1=E3=83=B3=E3=83=88/=E3=83=87?= =?UTF-8?q?=E3=82=AF=E3=83=AA=E3=83=A1=E3=83=B3=E3=83=88=E6=BC=94=E7=AE=97?= =?UTF-8?q?=E5=AD=90=E3=81=AE=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/1-trial-session/08-loop/index.md | 47 +++++++++++++++++++++---- docs/1-trial-session/11-object/index.md | 15 -------- 2 files changed, 41 insertions(+), 21 deletions(-) diff --git a/docs/1-trial-session/08-loop/index.md b/docs/1-trial-session/08-loop/index.md index bfa122b20..585c32688 100644 --- a/docs/1-trial-session/08-loop/index.md +++ b/docs/1-trial-session/08-loop/index.md @@ -16,7 +16,7 @@ while 文を用いると、ある条件が満たされている間実行され let i = 0; while (i < 5) { document.write(i); - i += 1; + i += i + 1; } document.write("終了"); ``` @@ -55,8 +55,8 @@ while (条件式) { let i = 1; let sum = 0; while (i <= 10) { - sum += i; - i += 1; + sum = sum + i; + i = i + 1; } document.write(sum); ``` @@ -64,6 +64,41 @@ document.write(sum); +:::tip 複合代入演算子、インクリメント演算子 + +**複合代入演算子** [(MDN)](https://developer.mozilla.org/ja/docs/Web/JavaScript/Guide/Expressions_and_Operators#%E4%BB%A3%E5%85%A5%E6%BC%94%E7%AE%97%E5%AD%90) は、計算と代入を同時に行うことができる演算子です。 + +`x += y` は、`x = x + y` という意味になります。他にも `-=` や `*=` などの演算子が定義されています。`x -= y` は`x = x - y`、`x *= y` は`x = x * y` という意味になります。 + +複合代入演算子を用いると、 + +```javascript +i = i + 1; +``` + +は以下のように書き換えることができます。 + +```javascript +i += 1; +``` + +**インクリメント演算子** [(MDN)](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Operators/Increment) は、与えられた変数に1を足します。 +一方、**デクリメント演算子** [(MDN)](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Operators/Decrement) は、与えられた変数から1を引きます。 + +`x++` は `x += 1` (= `x = x + 1`)、 `y--` は `y -= 1` (= `y = y - 1`) という意味になります。 +インクリメント演算子を使うと、 + +```javascript +i = i + 1; +``` + +は以下のように書き換えることができます。 + +```javascript +i++; +``` + +::: ## for 文 @@ -72,7 +107,7 @@ document.write(sum); 先ほどのプログラムは、 `for` 文によって次のように書き換えられます。 ```javascript -for (let i = 0; i < 5; i += 1) { +for (let i = 0; i < 5; i++) { document.write(i); } document.write("終了"); @@ -115,8 +150,8 @@ document.write(sum); `for` 文や `while` 文は、ネストして使用することができます。次のプログラムは、`(x, y) = (0, 0)` から始まって `(x, y) = (4, 4)` まで画面に表示します。 ```javascript -for (let x = 0; x < 5; x += 1) { - for (let y = 0; y < 5; y += 1) { +for (let x = 0; x < 5; x++) { + for (let y = 0; y < 5; y++) { document.write(`(x, y) = (${x}, ${y})
`); } } diff --git a/docs/1-trial-session/11-object/index.md b/docs/1-trial-session/11-object/index.md index d72eee78e..9b8644c18 100644 --- a/docs/1-trial-session/11-object/index.md +++ b/docs/1-trial-session/11-object/index.md @@ -50,26 +50,11 @@ let person = { ドット記号を用いることで、オブジェクトプロパティを取得・変更できます。通常の変数のように扱えます。 -```javascript -person.age = person.age + 1; -document.write(person.age); -``` - -:::tip 複合代入演算子 - -[複合代入演算子](https://developer.mozilla.org/ja/docs/Web/JavaScript/Guide/Expressions_and_Operators#%E4%BB%A3%E5%85%A5%E6%BC%94%E7%AE%97%E5%AD%90)は、計算と代入を同時に行うことができる演算子です。 - -`x += y` は、`x = x + y` という意味になります。他にも `-=` や `*=` などの演算子が定義されています。`x -= y` は`x = x - y`、`x *= y` は`x = x * y` という意味になります。 - -複合代入演算子を用いると、先ほどのプログラムは以下のように書くことができます。 - ```javascript person.age += 1; document.write(person.age); ``` -::: - ## 課題

オブジェクトの一種なので、関数引数戻り値として使用できます。

From ba5c8bb0d503d51013c323be357eaf978b2e5531 Mon Sep 17 00:00:00 2001 From: Fridge0 Date: Tue, 26 Sep 2023 14:35:20 +0900 Subject: [PATCH 02/11] (shouldve) fixed tip error --- docs/1-trial-session/08-loop/index.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/1-trial-session/08-loop/index.md b/docs/1-trial-session/08-loop/index.md index 585c32688..4f039d105 100644 --- a/docs/1-trial-session/08-loop/index.md +++ b/docs/1-trial-session/08-loop/index.md @@ -16,7 +16,7 @@ while 文を用いると、ある条件が満たされている間実行され let i = 0; while (i < 5) { document.write(i); - i += i + 1; + i = i + 1; } document.write("終了"); ``` @@ -64,6 +64,7 @@ document.write(sum); + :::tip 複合代入演算子、インクリメント演算子 **複合代入演算子** [(MDN)](https://developer.mozilla.org/ja/docs/Web/JavaScript/Guide/Expressions_and_Operators#%E4%BB%A3%E5%85%A5%E6%BC%94%E7%AE%97%E5%AD%90) は、計算と代入を同時に行うことができる演算子です。 From 316f9db85f6398b099da3edb177b447f06f93daf Mon Sep 17 00:00:00 2001 From: Fridge0 Date: Tue, 26 Sep 2023 15:01:23 +0900 Subject: [PATCH 03/11] =?UTF-8?q?=E8=A6=8B=E3=82=84=E3=81=99=E3=81=84?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB=E3=82=B9=E3=83=9A=E3=83=BC=E3=82=B7?= =?UTF-8?q?=E3=83=B3=E3=82=B0=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/1-trial-session/08-loop/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/1-trial-session/08-loop/index.md b/docs/1-trial-session/08-loop/index.md index 4f039d105..a9b3c3357 100644 --- a/docs/1-trial-session/08-loop/index.md +++ b/docs/1-trial-session/08-loop/index.md @@ -86,7 +86,7 @@ i += 1; **インクリメント演算子** [(MDN)](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Operators/Increment) は、与えられた変数に1を足します。 一方、**デクリメント演算子** [(MDN)](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Operators/Decrement) は、与えられた変数から1を引きます。 -`x++` は `x += 1` (= `x = x + 1`)、 `y--` は `y -= 1` (= `y = y - 1`) という意味になります。 +`x++` は `x = x + 1`(=`x += 1`)、 `y--` は `y = y - 1` (=`y -= 1`) という意味になります。 インクリメント演算子を使うと、 ```javascript From 111231e0b22a463f7aebbffc1e0b9361f509a8b7 Mon Sep 17 00:00:00 2001 From: Fridge0 Date: Tue, 26 Sep 2023 16:11:22 +0900 Subject: [PATCH 04/11] changed index.md --- docs/1-trial-session/08-loop/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/1-trial-session/08-loop/index.md b/docs/1-trial-session/08-loop/index.md index a9b3c3357..6fbed0780 100644 --- a/docs/1-trial-session/08-loop/index.md +++ b/docs/1-trial-session/08-loop/index.md @@ -43,7 +43,7 @@ while (条件式) { 1 から 10 までの整数の合計を計算するプログラムを作ってみましょう。 -:::tip ヒント +:::info ヒント `1` から `10` まで順番に増えていく変数 `i` と、合計値を保存しておく変数 `sum` を用意しましょう。 From 21c540815177a5515921ce5e813377be58775363 Mon Sep 17 00:00:00 2001 From: frgd <137767097+Fridge0@users.noreply.github.com> Date: Wed, 27 Sep 2023 09:51:49 +0900 Subject: [PATCH 05/11] =?UTF-8?q?MDN=E3=83=AA=E3=83=B3=E3=82=AF=E3=82=92?= =?UTF-8?q?=E5=8D=98=E8=AA=9E=E3=81=AB=E7=9B=B4=E6=8E=A5=E7=B4=90=E3=81=A5?= =?UTF-8?q?=E3=81=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/1-trial-session/08-loop/index.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/1-trial-session/08-loop/index.md b/docs/1-trial-session/08-loop/index.md index 6fbed0780..5faa12383 100644 --- a/docs/1-trial-session/08-loop/index.md +++ b/docs/1-trial-session/08-loop/index.md @@ -67,7 +67,7 @@ document.write(sum); :::tip 複合代入演算子、インクリメント演算子 -**複合代入演算子** [(MDN)](https://developer.mozilla.org/ja/docs/Web/JavaScript/Guide/Expressions_and_Operators#%E4%BB%A3%E5%85%A5%E6%BC%94%E7%AE%97%E5%AD%90) は、計算と代入を同時に行うことができる演算子です。 +[**複合代入演算子**](https://developer.mozilla.org/ja/docs/Web/JavaScript/Guide/Expressions_and_Operators#%E4%BB%A3%E5%85%A5%E6%BC%94%E7%AE%97%E5%AD%90) は、計算と代入を同時に行うことができる演算子です。 `x += y` は、`x = x + y` という意味になります。他にも `-=` や `*=` などの演算子が定義されています。`x -= y` は`x = x - y`、`x *= y` は`x = x * y` という意味になります。 @@ -83,8 +83,8 @@ i = i + 1; i += 1; ``` -**インクリメント演算子** [(MDN)](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Operators/Increment) は、与えられた変数に1を足します。 -一方、**デクリメント演算子** [(MDN)](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Operators/Decrement) は、与えられた変数から1を引きます。 +[**インクリメント演算子**](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Operators/Increment) は、与えられた変数に1を足します。 +一方、[**デクリメント演算子**](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Operators/Decrement) は、与えられた変数から1を引きます。 `x++` は `x = x + 1`(=`x += 1`)、 `y--` は `y = y - 1` (=`y -= 1`) という意味になります。 インクリメント演算子を使うと、 From aa060b1dbbd2c01f3a1f779093e5e6b2aca87ce3 Mon Sep 17 00:00:00 2001 From: frgd <137767097+Fridge0@users.noreply.github.com> Date: Wed, 27 Sep 2023 14:01:47 +0900 Subject: [PATCH 06/11] =?UTF-8?q?=5Fsamples=E3=81=AEfor=E6=96=87sync?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/1-trial-session/08-loop/_samples/answer-for/script.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/1-trial-session/08-loop/_samples/answer-for/script.js b/docs/1-trial-session/08-loop/_samples/answer-for/script.js index e4ff8fa63..4464405a7 100644 --- a/docs/1-trial-session/08-loop/_samples/answer-for/script.js +++ b/docs/1-trial-session/08-loop/_samples/answer-for/script.js @@ -1,5 +1,5 @@ let sum = 0; -for (let i = 1; i <= 10; i += 1) { - sum += i; +for (let i = 1; i <= 10; i++) { + sum++; } document.write(sum); From 0501f6bf0d50c5e565788c7f45c96bc6aabd7dbe Mon Sep 17 00:00:00 2001 From: frgd <137767097+Fridge0@users.noreply.github.com> Date: Sat, 30 Sep 2023 20:50:56 +0900 Subject: [PATCH 07/11] =?UTF-8?q?++=E6=BC=94=E7=AE=97=E5=AD=90=E6=B6=88?= =?UTF-8?q?=E5=8E=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/1-trial-session/08-loop/index.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/1-trial-session/08-loop/index.md b/docs/1-trial-session/08-loop/index.md index 5faa12383..d166ccf53 100644 --- a/docs/1-trial-session/08-loop/index.md +++ b/docs/1-trial-session/08-loop/index.md @@ -83,6 +83,7 @@ i = i + 1; i += 1; ``` + + ::: + ## for 文 `for` 文は、`while` 文にほんの少しだけ機能を追加したものになります。 @@ -151,8 +155,8 @@ document.write(sum); `for` 文や `while` 文は、ネストして使用することができます。次のプログラムは、`(x, y) = (0, 0)` から始まって `(x, y) = (4, 4)` まで画面に表示します。 ```javascript -for (let x = 0; x < 5; x++) { - for (let y = 0; y < 5; y++) { +for (let x = 0; x < 5; x += 1) { + for (let y = 0; y < 5; y += 1) { document.write(`(x, y) = (${x}, ${y})
`); } } From a4fbeef474752fcad6f127f95b470908f7bbd7b6 Mon Sep 17 00:00:00 2001 From: frgd <137767097+Fridge0@users.noreply.github.com> Date: Sun, 1 Oct 2023 14:44:52 +0900 Subject: [PATCH 08/11] =?UTF-8?q?++=E6=BC=94=E7=AE=97=E5=AD=90=E3=81=AE?= =?UTF-8?q?=E9=99=A4=E5=8E=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/1-trial-session/08-loop/_samples/answer-for/script.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/1-trial-session/08-loop/_samples/answer-for/script.js b/docs/1-trial-session/08-loop/_samples/answer-for/script.js index 4464405a7..e4ff8fa63 100644 --- a/docs/1-trial-session/08-loop/_samples/answer-for/script.js +++ b/docs/1-trial-session/08-loop/_samples/answer-for/script.js @@ -1,5 +1,5 @@ let sum = 0; -for (let i = 1; i <= 10; i++) { - sum++; +for (let i = 1; i <= 10; i += 1) { + sum += i; } document.write(sum); From 18ad721e54f53f87fcdfb401810d555a4c0b3d91 Mon Sep 17 00:00:00 2001 From: frgd <137767097+Fridge0@users.noreply.github.com> Date: Sun, 1 Oct 2023 14:46:01 +0900 Subject: [PATCH 09/11] =?UTF-8?q?:::info=20=E3=83=92=E3=83=B3=E3=83=88=20?= =?UTF-8?q?=E3=81=8B=E3=82=89:::tip=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/1-trial-session/08-loop/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/1-trial-session/08-loop/index.md b/docs/1-trial-session/08-loop/index.md index d166ccf53..31557481b 100644 --- a/docs/1-trial-session/08-loop/index.md +++ b/docs/1-trial-session/08-loop/index.md @@ -43,7 +43,7 @@ while (条件式) { 1 から 10 までの整数の合計を計算するプログラムを作ってみましょう。 -:::info ヒント +::: tip `1` から `10` まで順番に増えていく変数 `i` と、合計値を保存しておく変数 `sum` を用意しましょう。 From f7d79e4b18d0b5551532eb06be58c4ae8741d850 Mon Sep 17 00:00:00 2001 From: Fridge0 Date: Sun, 1 Oct 2023 23:37:20 +0900 Subject: [PATCH 10/11] =?UTF-8?q?=E6=95=99=E6=9D=90=E3=81=ABsync?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/1-trial-session/08-loop/_samples/answer-while/script.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/1-trial-session/08-loop/_samples/answer-while/script.js b/docs/1-trial-session/08-loop/_samples/answer-while/script.js index c21ec7d25..20a12a83f 100644 --- a/docs/1-trial-session/08-loop/_samples/answer-while/script.js +++ b/docs/1-trial-session/08-loop/_samples/answer-while/script.js @@ -1,7 +1,7 @@ let i = 1; let sum = 0; while (i <= 10) { - sum += i; - i += 1; + sum = sum + i; + i = i + 1; } document.write(sum); From 5435284941a194e8b4099cb33d3cceeff8cb15bf Mon Sep 17 00:00:00 2001 From: Fridge0 Date: Sun, 1 Oct 2023 23:37:31 +0900 Subject: [PATCH 11/11] =?UTF-8?q?=E3=82=82=E3=82=8D=E3=82=82=E3=82=8D?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/1-trial-session/08-loop/index.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/1-trial-session/08-loop/index.md b/docs/1-trial-session/08-loop/index.md index 31557481b..b65eb9a4d 100644 --- a/docs/1-trial-session/08-loop/index.md +++ b/docs/1-trial-session/08-loop/index.md @@ -43,7 +43,7 @@ while (条件式) { 1 から 10 までの整数の合計を計算するプログラムを作ってみましょう。 -::: tip +:::tip `1` から `10` まで順番に増えていく変数 `i` と、合計値を保存しておく変数 `sum` を用意しましょう。 @@ -65,7 +65,7 @@ document.write(sum); -:::tip 複合代入演算子、インクリメント演算子 +:::tip 複合代入演算子 [**複合代入演算子**](https://developer.mozilla.org/ja/docs/Web/JavaScript/Guide/Expressions_and_Operators#%E4%BB%A3%E5%85%A5%E6%BC%94%E7%AE%97%E5%AD%90) は、計算と代入を同時に行うことができる演算子です。 @@ -112,7 +112,7 @@ i++; 先ほどのプログラムは、 `for` 文によって次のように書き換えられます。 ```javascript -for (let i = 0; i < 5; i++) { +for (let i = 0; i < 5; i += 1) { document.write(i); } document.write("終了");