Skip to content

Instantly share code, notes, and snippets.

@nocodesupplyco
Created December 19, 2022 16:32
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 nocodesupplyco/c419e641950da1377987f1b70f0d3ba1 to your computer and use it in GitHub Desktop.
Save nocodesupplyco/c419e641950da1377987f1b70f0d3ba1 to your computer and use it in GitHub Desktop.
Simple Countdown Timer in Seconds
<span id="seconds">10</span>
<script>
timeLeft = 10;
function countdown() {
timeLeft--;
document.getElementById("seconds").innerHTML = String(timeLeft);
if (timeLeft > 0) {
setTimeout(countdown, 1000);
}
}
setTimeout(countdown, 1000);
</script>
<!-- See a test example here: https://codepen.io/cmoen89/pen/yLKoYxJ?editors=1010 -->
<span id="seconds">0</span>
<script>
numStart = 0;
numEnd = 10;
function countup() {
numStart++;
document.getElementById("seconds").innerHTML = String(numStart);
if (numStart < numEnd) {
setTimeout(countup, 1000);
}
}
setTimeout(countup, 1000);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment