0

I have a code with me for decrementing a timer with count equal to 6 but I want to decrement the value of count with format hrs:min:sec like this 00:00:10

function countdown() {
// starts countdown
if (count == 0) {
// time is up
} else {
count--;
t = setTimeout("countdown()", 1000);
}
};

where count will be 00:00:10 for 10 sec. How to decrement the timer ? Can anyone help me on this ?

Ancy
  • 33
  • 7

1 Answers1

0

Something like this will do what you need:

function showCountdown(countSeconds)
{  
   var countStatus = new Date(1000 * countSeconds).toISOString().substr(11, 8);
   document.getElementById('output').innerHTML = "Count: " + countStatus;
}
var count = 10;

function countdown() {
  // starts countdown
  if (count === 0) {
     return;
  }
  count--;
  setTimeout(countdown, 1000);
  showCountdown(count);
  
};

countdown();
<div id="output">
</div>

I've updated the JSFiddle to format as HH:mm:ss JSFiddle: https://jsfiddle.net/8uhq0vej/7/

Terry Lennox
  • 29,471
  • 5
  • 28
  • 40