我有一个程序随机生成两个数字(x和y)并要求用户将它们相乘。一旦它们相乘,它就会告诉它们是否正确或错误。我遇到问题的是,如果他们得到正确的答案,那么它应该生成一组新的数字。我不确定如何让程序再次执行该功能。它也必须清除答案字段,无论它们是对还是错。谢谢!
struct task_struct find_task_by_pid(pid_t pid);
答案 0 :(得分:1)
你没有调用genQuestion函数,重新定义它是没有意义的。
// function that is performed when the button "check answer" is clicked. It will generate one of 4 answers depending
//if it's right or wrong and will add 1 to the value of total. If it's incorrect it won't add anything
function buttonPressed() {
var correctans = correct[Math.floor(Math.random() * 4)]; // randomly selecting an answer if it's correct
var incorrectans = incorrect[Math.floor(Math.random() * 4)]; // randomly selecting an answer if it's incorrect
var answer = document.getElementById('answer').value;
if (answer == x * y) // correct
{
//call genQuestion to create new question
genQuestion();
window.alert(correctans);
var total = parseInt(document.getElementById('total').value)++;
}
else { // incorrect
window.alert(incorrectans);
}
//clear 'answer' field
document.getElementById('answer').value = '';
}