Javascript, countdown timer and display text

I am doing 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 delete seconds when it gets 0 seconds and shows "Are you ready!" message.

Can anyone help?

+6
source share
3 answers
 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 an example

+20
source
 document.getElementById('timer_div').innerHTML = "You are Ready!"; 
+4
source
 <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> 
0
source

Source: https://habr.com/ru/post/912297/


All Articles