Skip to content

Instantly share code, notes, and snippets.

@Risyandi
Created March 11, 2023 10:47
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 Risyandi/53138f76b1ddf714609a50e73b5f8dad to your computer and use it in GitHub Desktop.
Save Risyandi/53138f76b1ddf714609a50e73b5f8dad to your computer and use it in GitHub Desktop.
// Set initial countdown time to 60 seconds
var countdown = 60;
// Update the timer display every second
setInterval(function() {
countdown--;
var seconds = countdown % 60;
var minutes = Math.floor(countdown / 60);
// Add leading zero to seconds if less than 10
if (seconds < 10) {
seconds = "0" + seconds;
}
// Format the timer display string
var timerDisplay = minutes + ":" + seconds;
// Update the timer display element on the page
document.getElementById("timer").innerHTML = timerDisplay;
}, 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment