Countdown Timer
Posted: Mon Sep 26, 2016 8:15 pm
See It In Action - https://mikethedj4.github.io/kodeWeave/ ... 73f5a42ab6
Here we go a pretty basic tutorial.
We're going to be using setInterval for our timer.
In this function, we're going to change the text or HTML of an element to show the current countdown number.
When it reaches 0 we're going to clear the interval and tell the user they're being redirected.
Full Javascript:
Here we go a pretty basic tutorial.
We're going to be using setInterval for our timer.
Code: Select all
Notice inside of setInterval a function called countDown() is being called. var interval = setInterval(countDown, 1000);
In this function, we're going to change the text or HTML of an element to show the current countdown number.
When it reaches 0 we're going to clear the interval and tell the user they're being redirected.
Full Javascript:
Code: Select all
As you can see it's that easy var interval, count = 5;
countDown()
interval = setInterval(countDown, 1000);
function countDown() {
document.body.innerHTML = count;
if(count === 0) {
clearInterval(interval)
document.body.innerHTML = "Redirecting to .....";
} else {
count--;
}
}