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

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
	  startCountDown(30, 1000, myFunction);
   setTimeout(function() {
      // repeat
      countDownObj.count(i - 1);
   //set it going

function myFunction(){};


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


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