Skip to content

Commit 7a43ec9

Browse files
authored
Merge pull request #273 from ut-code/fix-lecture10-restaurants-rating
2 parents d4926be + ac940b7 commit 7a43ec9

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

docs/6-exercise/9-fetch-api/_samples/restaurants/server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ app.post("/register", (request, response) => {
2222

2323
app.post("/rate", (request, response) => {
2424
const index = request.body.index;
25-
restaurants[index].totalRating += Number(request.body.points); // 文字列を数値に変換
25+
restaurants[index].totalRating += Number(request.body.rating); // 文字列を数値に変換
2626
restaurants[index].numRatings += 1;
2727

2828
if (restaurants[index].numRatings !== 0) {

docs/6-exercise/9-fetch-api/_samples/restaurants/static/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<th>お店を評価</th>
1717
<td>
1818
<select id="name-select"></select>
19-
<select id="points-select">
19+
<select id="rating-select">
2020
<option value="5">☆5</option>
2121
<option value="4">☆4</option>
2222
<option value="3">☆3</option>

docs/6-exercise/9-fetch-api/_samples/restaurants/static/script.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
const restaurantList = document.getElementById("restaurant-list");
22
const nameInput = document.getElementById("name-input");
33
const nameSelect = document.getElementById("name-select");
4-
const pointsSelect = document.getElementById("points-select");
4+
const ratingSelect = document.getElementById("rating-select");
55

66
setInterval(async () => {
7-
// nameSelect にも pointsSelect にもフォーカスが当たっていない際にのみ、要素を再生成する
7+
// nameSelect にも ratingSelect にもフォーカスが当たっていない際にのみ、要素を再生成する
88
if (
99
document.activeElement !== nameSelect &&
10-
document.activeElement !== pointsSelect
10+
document.activeElement !== ratingSelect
1111
) {
1212
const response = await fetch("/restaurants");
1313
const restaurants = await response.json();
@@ -45,10 +45,10 @@ document.getElementById("register-button").onclick = async () => {
4545

4646
document.getElementById("rate-button").onclick = async () => {
4747
const index = nameSelect.value;
48-
const points = pointsSelect.value;
48+
const rating = ratingSelect.value;
4949
await fetch("/rate", {
5050
method: "post",
5151
headers: { "Content-Type": "application/json" },
52-
body: JSON.stringify({ index: index, points: points }),
52+
body: JSON.stringify({ index: index, rating: rating }),
5353
});
5454
};

docs/6-exercise/9-fetch-api/index.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import restaurantsVideo from "./restaurants.mp4"
2020
- 選択式のメニューを作るには `select` タグを用いましょう。
2121

2222
```html title="index.html"
23-
<select id="points-select">
23+
<select id="rating-select">
2424
<option value="5">☆5</option>
2525
<option value="4">☆4</option>
2626
<option value="3">☆3</option>
@@ -44,7 +44,7 @@ import restaurantsVideo from "./restaurants.mp4"
4444
```javascript title="script.js"
4545
if (
4646
document.activeElement !== nameSelect &&
47-
document.activeElement !== pointsSelect
47+
document.activeElement !== ratingSelect
4848
) {
4949
// 再描画
5050
}
@@ -71,7 +71,7 @@ app.post("/register", (request, response) => {
7171

7272
app.post("/rate", (request, response) => {
7373
const index = request.body.index;
74-
restaurants[index].totalRating += Number(request.body.points); // 文字列を数値に変換
74+
restaurants[index].totalRating += Number(request.body.rating); // 文字列を数値に変換
7575
restaurants[index].numRatings += 1;
7676

7777
if (restaurants[index].numRatings !== 0) {
@@ -88,10 +88,10 @@ app.post("/rate", (request, response) => {
8888

8989
```javascript title="static/script.js"
9090
setInterval(async () => {
91-
// nameSelect にも pointsSelect にもフォーカスが当たっていない際にのみ、要素を再生成する
91+
// nameSelect にも ratingSelect にもフォーカスが当たっていない際にのみ、要素を再生成する
9292
if (
9393
document.activeElement !== nameSelect &&
94-
document.activeElement !== pointsSelect
94+
document.activeElement !== ratingSelect
9595
) {
9696
const response = await fetch("/restaurants");
9797
const restaurants = await response.json();

0 commit comments

Comments
 (0)