So I'm trying to have a difficulty setting in a game I'm making in JavaScript. The hard mode has a shorter timer. I've tried shortening the time remaining variable with an if statement but it doesn't change the timer in the game.
<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>
I'm still very new to JavaScript so I'm aware I might be doing this completely wrong.
Aucun commentaire:
Enregistrer un commentaire