-
-
Save nocodesupplyco/c419e641950da1377987f1b70f0d3ba1 to your computer and use it in GitHub Desktop.
Simple Countdown Timer in Seconds
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
<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> |
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
<!-- 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