Created
October 26, 2021 16:26
-
-
Save LuisPaGarcia/f2fc7be09852d01f3709dda87441ed9f 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
function startTimer(duration) { | |
var timer = duration, minutes, seconds; | |
var intervalId = setInterval(function () { | |
minutes = parseInt(timer / 60, 10); | |
seconds = parseInt(timer % 60, 10); | |
minutes = minutes < 10 ? "0" + minutes : minutes; | |
seconds = seconds < 10 ? "0" + seconds : seconds; | |
console.log(minutes + ":" + seconds); | |
if (--timer < 0) { | |
clearInterval(intervalId); | |
} | |
}, 1000); | |
} | |
startTimer(15) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment