Skip to content

Commit 26f875d

Browse files
committed
Merge branch 'master' of https://github.com/ut-code/utcode-learn
2 parents ecf4a70 + a745332 commit 26f875d

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!doctype html>
2+
<html lang="ja">
3+
<head>
4+
<meta charset="utf-8" />
5+
<title>Title</title>
6+
</head>
7+
<body>
8+
<ul id="student-list"></ul>
9+
<script src="./script.js"></script>
10+
</body>
11+
</html>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const students = ["Hazel", "Dorian", "Scarlett", "Daisy"];
2+
3+
const studentList = document.getElementById("student-list");
4+
studentList.innerHTML = students
5+
.map((student) => `<li>${student}</li>`)
6+
.join("");

docs/2-browser-apps/04-anonymous-function/index.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,35 @@ const stars = rates.map((rate) => "★".repeat(rate));
116116

117117
## 課題
118118

119+
先ほどの[`Array#map` メソッド](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Array/map)を用いてみましょう。`students` 変数に格納されている名前を箇条書きにしてください。
120+
121+
```javascript
122+
const students = ["Hazel", "Dorian", "Scarlett", "Daisy"];
123+
// ここで HTML 要素を取得し、学生の名前をリストアイテムとして表示
124+
```
125+
126+
:::info ヒント
127+
128+
- `innerHTML` プロパティにより、HTML要素を取得・変更できます。
129+
- 箇条書きには `ul` タグや `li` タグを使用します。
130+
- `join` メソッドを配列要素を指定された文字列で連結するのに使います。
131+
132+
:::
133+
134+
<Answer>
135+
136+
```javascript
137+
const students = ["Hazel", "Dorian", "Scarlett", "Daisy"];
138+
const studentList = document.getElementById("student-list");
139+
studentList.innerHTML = students
140+
.map((student) => `<li>${student}</li>`)
141+
.join("");
142+
```
143+
144+
<ViewSource url={import.meta.url} path="_samples/map" />
145+
146+
</Answer>
147+
119148
`scores` 変数には、各必修科目の点数が格納されているとします。全ての要素が 50 点以上であることを確認するには、何というメソッドを使うのが適切か調べてみてください。また、実際にそのメソッドを用いて点数を確認してみてください。
120149

121150
```javascript

0 commit comments

Comments
 (0)