Skip to content

Instantly share code, notes, and snippets.

@LuisPaGarcia
Created October 26, 2021 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LuisPaGarcia/f2fc7be09852d01f3709dda87441ed9f to your computer and use it in GitHub Desktop.
Save LuisPaGarcia/f2fc7be09852d01f3709dda87441ed9f to your computer and use it in GitHub Desktop.
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