Reputation: 205
I am making a countdown timer with JavaScript.
Here is my script.
var seconds_left = 10;
var interval = setInterval(function() {
document.getElementById('timer_div').innerHTML = --seconds_left;
if (seconds_left <= 0)
{
//When it gets to 0 second, I want to show 'You are Ready!' text message.
}
}, 1000);
It starts to count from 10 seconds.
I want to eliminate seconds when it gets 0 second and show a 'You are Ready!' message.
Can anyone help?
Upvotes: 9
Views: 35270
Reputation: 1
<script>
TargetDate = "12/31/2020 5:00 AM";
DisplayFormat = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds.";
FinishMessage = "It is finally here!";
</script>
<script src="//scripts.hashemian.com/js/countdown.js"></script>
Upvotes: 0
Reputation: 7804
var seconds_left = 10;
var interval = setInterval(function() {
document.getElementById('timer_div').innerHTML = --seconds_left;
if (seconds_left <= 0)
{
document.getElementById('timer_div').innerHTML = 'You are ready';
clearInterval(interval);
}
}, 1000);
Here is the Example
Upvotes: 23
Reputation: 91912
document.getElementById('timer_div').innerHTML = "You are Ready!";
Upvotes: 4