所以我试图在我用JavaScript制作的游戏中设置难度。硬模式具有更短的计时器。我尝试使用if语句缩短剩余时间变量,但它不会改变游戏中的计时器。
<input type="checkbox" id="cb2" value="yes"> Hard
<script>
var timeRemain = 10;
if (document.getElementById("cb2").checked){
timeRemain == 5;
} else {
timeRemain == 10;
}
function countdown() {
var timerId = setTimeout(countdown, 1000);
if (timeRemain == 0) {
clearTimeout(timerId);
} else {
timeRemain--;
document.getElementById("timer").innerHTML = timeRemain + ' seconds left!';
}
}
</script>
我仍然是JavaScript的新手,所以我知道我可能会完全错误。
答案 0 :(得分:0)
我很确定它应该是timeRemain = 5
而不是timeRemain == 5
,因为单=
表示分配值,而有两个或三个用于比较。
if (document.getElementById("cb2").checked){
timeRemain = 5;
} else {
timeRemain = 10;
}
答案 1 :(得分:0)
(let ([residue-classes (partition-4 (iota 30000))])
(time
(lambda ()
(n-par-map 2
busy-work-2
residue-classes))))
&#13;
var timeRemain = 10;
if (document.getElementById("cb2").checked)
timeRemain = 5;
else
timeRemain = 10;
countdown = () => {
var timerId = setTimeout(countdown, 1000);
if (timeRemain == 0)
clearTimeout(timerId);
else {
timeRemain--;
document.getElementById("timer").innerHTML = `${timeRemain} seconds left!`;
}
}
&#13;
<input type="checkbox" id="cb2" value="yes"> Hard
,而timeRemain == 5
更改了