0

So I wont to create a timer that counts down to certain hours.

For example; I might have 6 timers running simultaneously, each counting down to a specific hour ( 1st counts down to 12.00pm, second to 1.00pm, third to 2.00pm etc. ).

I've been able to do create an hourly countdown but this would only work for a single timer and I cant figure out how to go further than an hour...

Here is my current code which is executed every second by setInterval:

time  = new Date
mins  = do time.getMinutes
mins  = ( 59 - mins ) % 60
secs  = do time.getSeconds

if secs != 60
    secs = ( 59 - secs ) % 60
else
    secs = 0

time = [ Number( mins ), Number( secs ) ]

minutes = time[1]
seconds = time[2]

minutes = '0' + time[1] if time[1] < 10
seconds = '0' + time[2] if time[2] < 10

console.log minutes, seconds

Any help would be appreciated.

Thanks : )

Ashmore11
  • 178
  • 1
  • 1
  • 12

1 Answers1

0

Is this is what you need?

<html>
<head>

</head>
<body>
 <h1 id="header">Click on the following button to start counting for 6 hours, your will get a notification on your console window after 6 hours.</h1>
 <br>
 <input type="button" style="font-weight:bold;cursor:pointer;" value="Click Me to start Counting" onclick="

indicate(21600000);">
<script type="text/javascript">
   function indicate(milliseconds){
    var current = Date.now();
    var Date_future = current + milliseconds;
    var period_done = "not_done";
    console.log("Status: Count Started");
    while (Date.now()!==Date_future) {
      if (Date.now()==Date_future){
        period_done = "done";
      }
    } 
    console.log("Status: Count Stopped, 6 hours finished");

   }
</script>
</body>
</html>