window.onload = function() { startCountDown(180, 1000, myFunction); // set setdown here } function startCountDown(i, p, f) { var pause = p; var fn = f; var countDownObj = document.getElementById("countDown"); if (countDownObj == null) { alert("div not found, check your id"); return; } countDownObj.count = function(i) { countDownObj.innerHTML = i; if (i == 0) { fn(); return; } setTimeout(function() { countDownObj.count(i - 1); }, pause ); } countDownObj.count(i); } function myFunction() { alert("hi alex"); }and put div name
<div id="countDown"></div>