0

currentValue = 708295;
targetValue = 0;

function count() {
  if (currentValue > targetValue) {
    currentValue -= 1
  } else if (currentValue < targetValue) {
    currentValue += 1
  }
  document.getElementById('timeTo').innerHTML =
    'Total wordcount:'+ currentValue.toString();
  changeTime = 1000;
  if (Math.abs(currentValue - targetValue) <0) {
    changeTime = 1000 - Math.abs(currentValue - targetValue);
  }
  setTimeout(count,changeTime/1);
}
count()
<h1 id="timeTo">Starting</h1>

any help will be very useful, i m trying to learn javascricpt and i want to create count down.

I want number to go down every sec but so far i have created the function to count the number but its counting too fast

ANy help or any suggestions

Thanks

Blair
  • 117
  • 1
  • 8
  • You can view a complete example here: http://stackoverflow.com/questions/20618355/the-simplest-possible-javascript-countdown-timer – Brian Salta Mar 09 '16 at 16:35

1 Answers1

0

setTimeout second argument is miliseconds value, it should be set to 1000 if you want to tick every second.

jkordas
  • 155
  • 6