Created
August 14, 2019 14:11
-
-
Save sany2k8/f54191ef1485628cde4b48d177ec15b1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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