<script type="text/javascript">
var questions = [
['http://i.imgur.com/k0fBtYP.png','0'],
['http://i.imgur.com/1PwDTVY.png','1'],
['http://i.imgur.com/QKE9UFA.png','2'],
['http://i.imgur.com/XEGhtgB.png','3'],
['http://i.imgur.com/QhnCkAp.png','4'],
['http://i.imgur.com/JoL8tco.png','5'],
['http://i.imgur.com/tcZNls4.png','6'],
['http://i.imgur.com/V9DQI0p.png','7'],
['http://i.imgur.com/39ePipM.png','8'],
['http://i.imgur.com/16yFeMy.png','9'],
['http://i.imgur.com/UUo2yNc.png','10'],
['http://i.imgur.com/5sza6Wm.png','11'],
['http://i.imgur.com/ygPZBdY.png','12'],
['http://i.imgur.com/SwJYBRR.png','13'],
['http://i.imgur.com/wNdpJBX.png','14'],
['http://i.imgur.com/wUS7pDs.png','15'],
['http://i.imgur.com/OEI6ZYX.png','16']
];
var qNo = 0;
var correct = 0;
var cnt = 0;
function NextQuestion(response) {
if ((qNo < questions.length) && (response == questions[qNo][1])) { correct++; }
document.getElementById('score').innerHTML
= 'Your score is '+correct+'/'+(cnt+1);
qNo++;
if (qNo < questions.length) { document.getElementById('Pic').src = questions[qNo][0]; cnt++; }
else { alert('Quiz is done'); }
}
onload = function() {
document.getElementById('Pic').src = questions[0][0];
}
</script>
好吧,基本上我有 17 个问题和 17 个答案,使用数字 0-16 列出,我想做的是随机化图片显示的顺序,这样你就不能只找到一个模式而不回答它是的,我也无法弄清楚这一点,我想做到这一点,以便在回答每个问题后,会显示绿色正确或红色不正确,具体取决于如果您正确回答了上一个问题,有人可以帮忙吗?
最佳答案
抱歉,目前我必须赶时间,因此无法为您提供代码,但我可以为您提供需要遵循的步骤。
- 打乱数组 How to randomize (shuffle) a JavaScript array
- 编写一个循环遍历数组的简单循环
关于javascript - 我如何随机显示我的问题,使其现在始终相同? (JavaScript),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32813595/