Skip to content

Instantly share code, notes, and snippets.

@sany2k8
Created August 14, 2019 14:11
Show Gist options
  • Save sany2k8/f54191ef1485628cde4b48d177ec15b1 to your computer and use it in GitHub Desktop.
Save sany2k8/f54191ef1485628cde4b48d177ec15b1 to your computer and use it in GitHub Desktop.
var timeoutHandle;
function countdown(minutes, seconds) {
function tick() {
var counter = document.getElementById("timer");
counter.innerHTML =
minutes.toString() + ":" + (seconds < 10 ? "0" : "") + String(seconds);
seconds--;
if (seconds >= 0) {
timeoutHandle = setTimeout(tick, 1000);
} else {
if (minutes >= 1) {
// countdown(mins-1); never reach “00″ issue solved:Contributed by Victor Streithorst
setTimeout(function () {
countdown(minutes - 1, 59);
}, 1000);
}
}
if (seconds==0 && minutes ==0){
alert("Game over");
reset();
}
}
tick();
}
countdown(1, 00);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment