我正在尝试使用 JavaScript 构建数学测试应用程序。但是我对 FOR 语句有疑问,我想要它做的是为每个回答正确的问题在分数上加一分。为了测试它,我将分数设置为 0,用户 ID 将是用户输入,如果用户输入正确的答案,它会增加到 1,但它会一直增加到 10。有没有办法在第一个周期后停止计数并等到第二个周期等等直到它达到10?
<!doctype html>
<html>
<head>
</head>
<body>
<div id="scoreBlock"><span id="score">0</span></div>
<input type="text" id="userID"/>
<button onclick="begin();">Start</button>
<script>
function begin(){
var h= document.getElementById("score");
var user =document.getElementById("userID").value;
var test = "5";
for(h=0;h<=10;h++){
if(user==="5"){
document.getElementById("score").innerHTML= h;
}else if(!user==="5"){
alert("noting");
}
}//end of while
}//end of function
</script>
</body>
</html>