回答編集履歴
3
テキスト修正
answer
CHANGED
@@ -41,7 +41,9 @@
|
|
41
41
|
|
42
42
|
```
|
43
43
|
|
44
|
+
なお上記で、`wordsAry` の内容は、オブジェクトリテラルに書いたとおりの順番に沿った
|
44
|
-
|
45
|
+
`["white", "book", "car", "pencil", "watch"]`
|
46
|
+
には**必ずしもならない**のですが、目的がランダムサンプリングなのであれば順番は関係ないので、上記でも要件は満たされると思います。
|
45
47
|
|
46
48
|
- **動作確認用 CodePen:** [https://codepen.io/jun68ykt/pen/bGGgQwL?editors=0012](https://codepen.io/jun68ykt/pen/bGGgQwL?editors=0012)
|
47
49
|
|
2
テキスト修正
answer
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
ご質問に挙げられているコードのどこが拙いかというと、`words` は配列ではないので、`words.length` は意図している、 `5` という数値にはならず undefined になることです。
|
4
4
|
|
5
5
|
そのため、
|
6
|
-
- `Math.floor(Math.random() * words.length` は NaN になり、
|
6
|
+
- `Math.floor(Math.random() * words.length)` は NaN になり、
|
7
7
|
- `words[Math.floor(Math.random() * words.length)]` は undefined となって、
|
8
8
|
- `words[Math.floor(Math.random() * words.length)].word` は undefined のwordプロパティを読みにいこうとして、ご質問にあるエラーメッセージ
|
9
9
|
|
1
テキスト修正
answer
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
こんにちは
|
2
2
|
|
3
|
-
ご質問に挙げられているコードのどこ
|
3
|
+
ご質問に挙げられているコードのどこが拙いかというと、`words` は配列ではないので、`words.length` は意図している、 `5` という数値にはならず undefined になることです。
|
4
4
|
|
5
5
|
そのため、
|
6
6
|
- `Math.floor(Math.random() * words.length` は NaN になり、
|