I have a code for a Memory game with images. I took the reference for the game from this link:
In this code , the game has a clock/ timer. I would like to make this timer into a clock down timer setting a limit of 10 mins. I dont know how to change this timer into clock down time. Can someone help me out with this problem.
// @description game timer
var second = 0,
minute = 20;
hour = 0;
var timer = document.querySelector(".timer");
var interval;
function startTimer() {
interval = setInterval(function() {
timer.innerHTML = minute + "mins " + second + "secs";
second++;
if (second == 60) {
minute++;
second = 0;
}
if (minute == 60) {
hour++;
minute = 0;
}
}, 1000);
}
//reset timer
second = 0;
minute = 20;
hour = 0;
var timer = document.querySelector(".timer");
timer.innerHTML = "20 mins 0 secs";
clearInterval(interval);
startTimer();
<div class="timer">
</div>
Can someone show me how to change this normal timer into a countdown timer and help me out of this problem.
startTimer();
instead? – Chris G