Javascript countdown reset after some time interval

This is a simple countdown timer starting at 30 seconds from when the function is run and ending at 0. After reaching 0 it automatically reset the counter. It goes again to 30 second and this process is continued in a loop

<script>
window.onload = function() {
   startCountDown(30, 1000, myFunction);
}

function startCountDown(i, p, f) {
   var pause = p;
   var fn = f;
   var countDownObj = document.getElementById("countDown");

   countDownObj.count = function(i) {
      //write out count
      countDownObj.innerHTML = i;
      if (i == 0) {
      //execute function
      //fn();
	         
	  startCountDown(30, 1000, myFunction);
	  //stop
      return;
   }
   setTimeout(function() {
      // repeat
      countDownObj.count(i - 1);
      },
      pause  
      );
   }
   //set it going
   countDownObj.count(i);
}

function myFunction(){};

       
</script>

<div id="countDown"></div>

(1054)

About Zahidul Hossein Ripon

Zahidul Hossein Ripon a Bangladesh national, born in 1983 did Bachelor of Science in Computer Science and Engineering. At present, Mr. Ripon is working as a Managing Director in Coraltech Solutions. Before working with Coraltech Solutions, he worked in different reputed ICT industries in Bangladesh from year 2007. Mr. Ripon is one of the Associate Member of Bangladesh Computer Society. Mr. Ripon attended couple of Conference and Training, Seminars and events of ICT in Bangladesh and abroad. He is one of the co-author of few number of research publications in international scientific journals and proceedings.

,

No comments yet.

Leave a Reply


*