【发布时间】:2021-07-29 11:37:15
【问题描述】:
我正在尝试在 html、css、js 中创建一个刽子手游戏。 所以我现在要根据问题的显示方式对其进行随机化 -
创建随机数 - Math.floor((Math.random() * 10) + 1)
首先检查数组(这个数组包含哪些问题已经完成)是否有随机数
| if not | if yes |
|---|---|
| then allow the below statement to happen | then let the function run again and agiin until random number is not there in th array |
第一个问题基于随机数和第二个 olso 等等
但实际上我无法弄清楚如何检查数组中的随机数。我试过了:-
这行得通
function NextQuestion() {
let done = ['1','2'];
let random = Math.floor((Math.random() * 10) + 1);
let include = done.includes('1');
if (include == true) {
alert('true');// this works
}
}
这不是
function NextQuestion() {
let done = ['1','2'];
let random = Math.floor((Math.random() * 10) + 1);
let include = done.includes(random);
if (include == true) {
alert('true');// this does not works
}
}
不同之处在于第一个有 includes('1'); 但第二个有 includes(random);
你知道为什么会发生这种情况吗?如果你知道,请告诉我,并请给出解决这个问题的方法
提前致谢。
【问题讨论】:
-
随机是一个数字,你的数组包含字符串。
标签: javascript html css arrays