我正在制作一个教育网站,我需要一些帮助。
我有这段代码:
challenge1 = num1*num2;
challenge2 = num1*2+Math.floor(Math.random() *3) + 1;;
challenge3 = num1*num2+Math.floor(Math.random() *9) + 1;
challenge4 = num2+Math.floor(Math.random() *9) + 1;
makeButton(challenge1);
makeButton(challenge2);
makeButton(challenge3);
makeButton(challenge4);
function makeButton(number) {
btncount = btncount+1;
/* create a button */
var b = document.createElement('button');
b.setAttribute('class', 'pure-button');
b.setAttribute('onclick', `check(${number})`);
b.setAttribute('id', btncount);
b.textContent = number;
var buttons = document.getElementById("buttons");
buttons.appendChild(b);
}
<div id='buttons' class="pure-button-group" role="group"></div>
它有效,但很容易发现正确答案始终是第一个按钮。
有没有办法随机化这些顺序?谢谢。
牛魔王的故事
HUX布斯
鸿蒙传说
相关分类