gpt4 book ai didi

javascript - 错还是对? Javascript

转载 作者:行者123 更新时间:2023-11-30 16:20:43 24 4
gpt4 key购买 nike

我有 2 个按钮,正确和错误。当屏幕上弹出随机问题(vragen)时,其索引号 [1] 需要与答案(antw)索引号 [1] 相同。如果按下 G 按钮并且它很好,它必须说 yay,bad noo 并且当点击 F 时相同但然后相反!

window.onload = function start(){

var questions = [ "1 x 1 = 2",
"1 x 1 = 1",
"2 x 2 = 4",
"7 x 7 = 49",
"1 x 8 = 9",
"8 x 1 = 8",
"5 x 5 = 25",
"3 x 5 = 2"
];
var answers = [ false,
true,
true,
true,
false,
true,
true,
false
];

var rand = questions[Math.floor(Math.random() * questions.length)];
var randans = answers[Math.floor(Math.random() * answers.length)];
document.getElementById('quizzy').innerHTML = rand + "<br>";

document.getElementById('G').onclick = check1;
document.getElementById('F').onclick = check2;
function check1(){
if(rand == randans){
alert("a!");
}
}
};

和 HTML

<div id="section">
<h2>Goed of Fout?</h2>
<div id="quizzy"><script src="quiz.js"></script></div>
<img src="images/G_03.gif" width="200px" class="GF" id="G"/>
<img src="images/F_03.gif" width="200px" class="GF" id="F"/>
<img src="images/chick_03.png" width="100px" id="chick" />

最佳答案

试试这个。编辑:这个适用于 jQuery。

$( document ).ready(function() {

var vragen = ["1 x 1 = 2",
"1 x 1 = 1",
"2 x 2 = 4",
"7 x 7 = 49",
"1 x 8 = 9",
"8 x 1 = 8",
"5 x 5 = 25",
"3 x 5 = 2"
];
var antw = [false,
true,
true,
true,
false,
true,
true,
false
];

var a = Math.floor(Math.random() * vragen.length),
rand = vragen[a];
$('#quizzy').innerHTML = rand + "<br>";

$(".GF").onclick(function(){
if (antw[a] === true) {
alert("a!");
} else {
alert("boo!");
}
});
});

关于javascript - 错还是对? Javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34784064/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com