teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

map.lengthをmap.sizeへ変更

2020/07/14 03:46

投稿

Kaleidoscope
Kaleidoscope

スコア257

answer CHANGED
@@ -4,8 +4,9 @@
4
4
  ```
5
5
  //Math.floor(Math.random() * Math.floor(words.length))で 0~3の整数の乱数が生成される
6
6
  //keyは1~4となっているため1を足す。
7
- const randIndex =1+ Math.floor(Math.random() * Math.floor(words.length));
7
+ const randIndex =1+ Math.floor(Math.random() * Math.floor(words.size));
8
8
 
9
9
  //Map.get関数でvalueを取得する。keyは1~4の文字列のため、(""+num)として文字列に変換する。
10
10
  const word = words.get(""+randIndex);
11
- ```
11
+ ```
12
+ ※コメントを受けて修正しました。