Skip to content

Commit d5b77a6

Browse files
authored
Merge pull request #292 from ut-code/develop
`develop` を `master` にマージ
2 parents 7996280 + fe2d5c6 commit d5b77a6

File tree

12 files changed

+64
-48
lines changed

12 files changed

+64
-48
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
function incrementAge(person) {
22
person.age += 1;
3+
return person;
34
}
45

56
const tanaka = { name: "田中", age: 18 };
67
const nextYearTanaka = incrementAge(tanaka);
78
document.write(nextYearTanaka.age);
8-
9+
document.write(" ");
910
// 19 と表示されてしまう
1011
document.write(tanaka.age);

docs/2-browser-apps/02-constant/index.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ JavaScript において、それはコードを読んだ際に読みやすいか
3838
```javascript
3939
const person = { name: "田中", age: 18 };
4040
person.name = "佐藤"; // OK
41+
// 変数自体への再代入はできない
42+
// person = { name: "佐藤", age: 20 };
4143
```
4244

4345
:::
@@ -101,7 +103,7 @@ function incrementAge(person) {
101103
const tanaka = { name: "田中", age: 18 };
102104
const nextYearTanaka = incrementAge(tanaka);
103105
document.write(nextYearTanaka.age);
104-
106+
document.write(" ");
105107
// 19 と表示されてしまう
106108
document.write(tanaka.age);
107109
```

docs/2-browser-apps/04-class/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Answer from "@site/src/components/Answer";
99

1010
## <Term type="javascriptClass">クラス</Term>と<Term type="javascriptInstance">インスタンス</Term>
1111

12-
<Term type="javascriptObject">オブジェクト</Term>を使うと、複数の値をひとまとまりに扱うことができました。実世界においては、同じ<Term type="javascriptProperty">プロパティ</Term>(属性)を持つ<Term type="javascriptObject">オブジェクト</Term>を多く扱う場合が多いです。例えば、学生を<Term type="javascriptObject">オブジェクト</Term>として表すことを考えてみましょう。学生には必ず名前と年齢という属性があるはずなので、ひとまず `name``age` を<Term type="javascriptProperty">プロパティ</Term>に持つとしましょう。
12+
オブジェクトを使うと、複数の値をひとまとまりに扱うことができました。実世界においては、同じ<Term type="javascriptProperty">プロパティ</Term>(属性)を持つ<Term type="javascriptObject">オブジェクト</Term>を多く扱う場合が多いです。例えば、学生を<Term type="javascriptObject">オブジェクト</Term>として表すことを考えてみましょう。学生には必ず名前と年齢という属性があるはずなので、ひとまず `name``age` を<Term type="javascriptProperty">プロパティ</Term>に持つとしましょう。
1313

1414
```javascript
1515
const tanaka = {

docs/2-browser-apps/09-project/_samples/calender/script.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,24 @@ const endDate = new Date(year, month + 1, 0);
77
const calender = document.getElementById("calender");
88
const button = document.getElementById("button");
99

10-
//編集中の予定を追うための変数
10+
// 編集中の予定を追うための変数
1111
let editedLi = null;
1212

13-
//各日付の要素を格納するオブジェクト
13+
// 各日付の要素を格納するオブジェクト
1414
const container = {};
1515

16-
//曜日の行を作成
16+
// 曜日の行を作成
1717
const firstRow = document.createElement("tr");
1818
for (let i = 0; i < 7; i += 1) {
1919
const th = document.createElement("th");
2020
th.textContent = days[i];
2121
firstRow.appendChild(th);
2222
}
2323

24-
//曜日の行を追加
24+
// 曜日の行を追加
2525
calender.appendChild(firstRow);
2626

27-
//日付の行を作成
27+
// 日付の行を作成
2828
for (let x = 1; x <= 6; x += 1) {
2929
const tr = document.createElement("tr");
3030
calender.appendChild(tr);
@@ -51,7 +51,7 @@ for (let i = 1; i <= 42; i += 1) {
5151
}
5252
}
5353

54-
//予定を追加する関数
54+
// 予定を追加する関数
5555
function addTask(e) {
5656
const li = document.createElement("li");
5757
const input = document.createElement("input");
@@ -61,7 +61,7 @@ function addTask(e) {
6161
editedLi = li;
6262
}
6363

64-
//予定を固定する関数
64+
// 予定を固定する関数
6565
function fixTask(e) {
6666
if (e.keyCode === 13) {
6767
const input = editedLi.firstChild;
@@ -78,7 +78,7 @@ function fixTask(e) {
7878
}
7979
}
8080

81-
//予定を編集できるようにする関数
81+
// 予定を編集できるようにする関数
8282
function editTask(e) {
8383
editedLi = e.target.parentNode;
8484
const input = document.createElement("input");
@@ -87,17 +87,17 @@ function editTask(e) {
8787
editedLi.replaceChild(input, editedLi.firstChild);
8888
}
8989

90-
//予定を消す関数
90+
// 予定を消す関数
9191
function deleteTask() {
9292
editedLi.remove();
9393
button.style.visibility = "hidden";
9494
editedLi = null;
9595
}
9696

97-
//クリックしたときに実行される関数
97+
// クリックしたときに実行される関数
9898

9999
function clicked(e) {
100-
//予定を編集していないとき
100+
// 予定を編集していないとき
101101

102102
if (editedLi === null) {
103103
if (e.target.class === "task") {
@@ -111,7 +111,7 @@ function clicked(e) {
111111
addTask(e);
112112
}
113113
}
114-
//予定を編集中の時
114+
// 予定を編集中の時
115115
else {
116116
if (e.target.tagName !== "INPUT" && e.target.tagName !== "BUTTON") {
117117
button.style.visibility = "hidden";

docs/4-advanced/01-fetch-api/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import chatAppVideo from "./chat-app.mp4";
1212

1313
これまで、ブラウザが<Term type="serverClient">サーバー</Term>に対して<Term type="httpRequestResponse">リクエスト</Term>を送信するのは、リンクがクリックされたときや、フォームが送信されたときなど、ページの再読み込みが起こる場合のみでした。
1414

15-
しかしながら、ブラウザ上で動く JavaScript から利用できる **<Term type="api">FetchAPI</Term >** を用いると、任意のタイミングで<Term type="httpRequestResponse">リクエスト</Term>が発行できるようになります。<Term type="api">API</Term > は、アプリケーションプログラミングインターフェース(Application Programming Interface)の略で、あるソフトウェアの機能や管理するデータを、外部の他のソフトウェアで利用するための手順やデータ形式を定めた規約のことです。多くのソフトウェアが共通して利用する機能がまとめて提供されており、<Term type="api">API</Term > に従い短いコードを記述するだけでその機能を利用することができます。
15+
しかしながら、ブラウザ上で動く JavaScript から利用できる **Fetch <Term type="api">API</Term >** を用いると、任意のタイミングで<Term type="httpRequestResponse">リクエスト</Term>が発行できるようになります。<Term type="api">API</Term > は、アプリケーションプログラミングインターフェース(Application Programming Interface)の略で、あるソフトウェアの機能や管理するデータを、外部の他のソフトウェアで利用するための手順やデータ形式を定めた規約のことです。多くのソフトウェアが共通して利用する機能がまとめて提供されており、<Term type="api">API</Term > に従い短いコードを記述するだけでその機能を利用することができます。
1616
<Term type="serverClient">サーバー</Term>と<Term type="serverClient">クライアント</Term>、どちらで動く JavaScript なのかに注意しながら、次のプログラムを実行してみましょう。
1717

1818
```html title="/static/index.html の body 内"
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
let numberOfA = 19;
2-
let numberOfB = 22;
1+
let tanakaHandTotal = 19;
2+
let satoHandTotal = 22;
33

44
// 21を超えていた場合は0(最弱)として扱う
5-
if (numberOfA > 21) numberOfA = 0;
6-
if (numberOfB > 21) numberOfB = 0;
5+
if (tanakaHandTotal > 21) tanakaHandTotal = 0;
6+
if (satoHandTotal > 21) satoHandTotal = 0;
77

8-
if (numberOfA > numberOfB) {
9-
document.write("Aさんの勝ち");
10-
} else if (numberOfA < numberOfB) {
11-
document.write("Bさんの勝ち");
8+
if (tanakaHandTotal > satoHandTotal) {
9+
document.write("田中さんの勝ち");
10+
} else if (tanakaHandTotal < satoHandTotal) {
11+
document.write("佐藤さんの勝ち");
1212
} else {
1313
document.write("引き分け");
1414
}

docs/6-exercise/1-basis-of-web/_samples/truck/script.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ let box = 25;
22
let weight = 1000;
33

44
if (box <= 30 && weight <= 2000) {
5-
document.write("<p style='color: green'>出発できます</p>");
5+
document.write('<p style="color: green">出発できます</p>');
66
} else if (box > 30 && weight <= 2000) {
7-
document.write("<p style='color: red'>箱の数を減らしてください</p>");
7+
document.write('<p style="color: red">箱の数を減らしてください</p>');
88
} else if (box <= 30 && weight > 2000) {
9-
document.write("<p style='color: red'>重量を減らしてください</p>");
9+
document.write('<p style="color: red">重量を減らしてください</p>');
1010
} else {
11-
document.write("<p style='color: red'>箱の数と重量を減らしてください</p>");
11+
document.write('<p style="color: red">箱の数と重量を減らしてください</p>');
1212
}
File renamed without changes.

docs/6-exercise/1-basis-of-web/index.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -119,30 +119,30 @@ if (4 <= lengthOfName && lengthOfName <= 10) {
119119

120120
## 3. ブラックジャック
121121

122-
A さんと B さんの 2 人が、トランプゲームのブラックジャックで遊んでいます。ブラックジャックのルールは以下の通りとします。
122+
田中さんと佐藤さんの 2 人が、トランプゲームのブラックジャックで遊んでいます。ブラックジャックのルールは以下の通りとします。
123123

124124
- 2 人の手札の数字の合計を比べ、より大きい方が勝ちとなる。
125125
- ただし、どちらか 1 人の手札の数字の合計が 21 を超えていた場合、その人の負けとなる。
126126
- 2 人の手札の数字の合計が同じだった場合や、2 人とも 21 を超えていた場合は引き分けとなる。
127127

128-
A さんと B さんの手札の数字の合計をそれぞれ変数に入れておき、A さんと B さんのどちらが勝つか、あるいは引き分けかを表示するプログラムを作成してください。
128+
田中さんと佐藤さんの手札の数字の合計をそれぞれ変数に入れておき、田中さんと佐藤さんのどちらが勝つか、あるいは引き分けかを表示するプログラムを作成してください。
129129

130130
### 解答例
131131

132132
<Answer>
133133

134134
```javascript
135-
let numberOfA = 19;
136-
let numberOfB = 22;
135+
let tanakaHandTotal = 19;
136+
let satoHandTotal = 22;
137137

138138
// 21を超えていた場合は0(最弱)として扱う
139-
if (numberOfA > 21) numberOfA = 0;
140-
if (numberOfB > 21) numberOfB = 0;
139+
if (tanakaHandTotal > 21) tanakaHandTotal = 0;
140+
if (satoHandTotal > 21) satoHandTotal = 0;
141141

142-
if (numberOfA > numberOfB) {
143-
document.write("Aさんの勝ち");
144-
} else if (numberOfA < numberOfB) {
145-
document.write("Bさんの勝ち");
142+
if (tanakaHandTotal > satoHandTotal) {
143+
document.write("田中さんの勝ち");
144+
} else if (tanakaHandTotal < satoHandTotal) {
145+
document.write("佐藤さんの勝ち");
146146
} else {
147147
document.write("引き分け");
148148
}
@@ -237,13 +237,13 @@ function fibonacci(n) {
237237

238238
### ヒント
239239

240-
`document.write()` では文字列だけでなく、HTML 要素を出力することができます。
240+
`document.write()` は文字列だけでなく、HTML 要素を出力することができます。
241241

242242
```javascript title=script.js
243-
document.write("<p style='color: blue'>Hello World!</p>");
243+
document.write('<p style="color: blue">Hello World!</p>');
244244
```
245245

246-
![青いHello World](./blue-hello-world.jpeg)
246+
![青い Hello World](./blue-hello-world.jpg)
247247

248248
### 解答例
249249

@@ -254,13 +254,13 @@ let box = 25;
254254
let weight = 1000;
255255

256256
if (box <= 30 && weight <= 2000) {
257-
document.write("<p style='color: green'>出発できます</p>");
257+
document.write('<p style="color: green">出発できます</p>');
258258
} else if (box > 30 && weight <= 2000) {
259-
document.write("<p style='color: red'>箱の数を減らしてください</p>");
259+
document.write('<p style="color: red">箱の数を減らしてください</p>');
260260
} else if (box <= 30 && weight > 2000) {
261-
document.write("<p style='color: red'>重量を減らしてください</p>");
261+
document.write('<p style="color: red">重量を減らしてください</p>');
262262
} else {
263-
document.write("<p style='color: red'>箱の数と重量を減らしてください</p>");
263+
document.write('<p style="color: red">箱の数と重量を減らしてください</p>');
264264
}
265265
```
266266

docs/6-exercise/2-easy-apps/index.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,9 @@ ctx.fillRect(10, 10, 100, 100);
283283

284284
```html
285285
<button id="button">押してください</button>
286-
<div id="display"></div>
286+
<div id="tag-name-display"></div>
287+
<div id="display-x"></div>
288+
<div id="display-y"></div>
287289
```
288290

289291
```javascript

0 commit comments

Comments
 (0)