Search code examples
javascriptjquerycountdown

Countdown Counter Javascript or Jquery?


I am tryin to create a simple counter that counts backwards from 3 to 0 or 5 to 0 or whatever.

It's a timer for a questions so each number needs to be visible to the user.

I tried:

for (i=3;i>=0;i--){

   $(".timerInner").delay(500).text( i );

}

But had no luck.


Solution

  • Try this,

    var i =5;
    
    var timer = setInterval( calltimer, 500);
    
    function calltimer(){
        $(".timerInner").append( i );
    
        if(i == 0){
           clearInterval(timer);
        }
        i--;
    
    }