Countdown in java script - help


#1

<Below this line, in what way does your code behave incorrectly? Include ALL error messages.>
I wanna add more time to the countdown when an HTML button is clicked, where to add an amount of time -every time a button is clicked- in my code!
Thanx
ps : THIS IS A SIDE EXCERCISE BUT I HOPE YOU CAN HELP, I WANNA KNOW HOW ! :wink:

<script>
 var countDownDate = new Date("10/07/20 00:00:00").getTime();


 // Update the count down every 1 second
 var x = setInterval(function() {

     // Get todays date and time
     var now = new Date().getTime();
    
     // Find the distance between now an the count down date
     var distance = countDownDate - now;
    
     // Time calculations for days, hours, minutes and seconds
     var years = Math.floor((distance % (1000 * 60 * 60 * 24 * 30 * 12 * 356)) / (1000 * 60 * 60 * 24 * 30 * 12));
     var months = Math.floor((distance % (1000 * 60 * 60 * 24 * 30 * 12)) / (1000 * 60 * 60 * 24 * 30));
     var days = Math.floor((distance % (1000 * 60 * 60 * 24 * 30)) / (1000 * 60 * 60 * 24));
     var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 
 60));
     var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
     var seconds = Math.floor((distance % (1000 * 60)) / 1000);
    
    
     // Output the result in an element with id="demo"
     document.getElementById("demo").innerHTML = months +"m-"+ days + 
 "d - " + hours + ": " + minutes + ": " + seconds;
    
     // If the count down is over, write some text 
     if (distance < 0) {
         clearInterval(x);
         document.getElementById("demo").innerHTML = "EXPIRED";
    
 }
 }, 1000);
</script>

#2

seems you need to add settimeout:

you would need to add it to your JS code.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.