我创建了两个函数 (F1
和F2
)
F1
创建一个随机答案
F2
应该对生成的答案进行反馈F1
( if(antw == ant
)
我的问题是如何使用生成的F2
随机答案F1
,以便反馈正确?
var operators = ['+','-'];
function F1()
{
Z1 = document.getElementById("Z1");
Z2 = document.getElementById("Z2");
oper=document.getElementById("operator");
answer=document.getElementById("answer");
rZ1 = Math.floor((Math.random()*10));
rZ2 = Math.floor((Math.random()*10)+1);
op = operators[Math.floor(Math.random()*2)];
Z1.innerHTML=rZ1;
Z2.innerHTML=rZ2;
oper.innerHTML=op;
answer.innerHTML = eval(rZ1 + op + rZ2);
}
document.getElementById("button2").addEventListener("click", F2);
function F2()
{
antw = parseInt(document.getElementById("userAnswer").value, 10);
feedBack = document.getElementById("feedBack");
ant = document.getElementById("answer");
{
if(antw == ant) {
feedBack.textContent = "right";
} else {
feedBack.textContent = "wrong";
}
}
};
<button onclick="F1()"> New </button>
<p>
<label id="Z1"> </label>
<label id="operator"> </label>
<label id="Z2"> </label>
= <input id = "userAnswer" type=text>
<button id = "button2" >answer</button>
</p>
<p id = "feedBack"> </p>
<p><label id="answer"> </label></p>
慕村9548890
相关分类