Countdown Timer
3 posts
Page 1 of 1
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--;
}
}

A basic timer but I like it.
I'm embarrassed to say that I struggled with setinterval when I was trying to get our site scripts working
Nice little tutorial
I'm embarrassed to say that I struggled with setinterval when I was trying to get our site scripts working

Nice little tutorial

Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
3 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023