I am trying to make a start a timer clock MM:SS after a certain given interval on page.
I have tried setinterval function but the time it is showing resets after 3 seconds......i wanted it to be call the function only once so the internal function "TIMER CLOCK" keeps going on
setInterval(function timerx(){
var timer = setInterval(clock, 1000);
var msec = 00;
var sec = 00;
var min = 00;
function clock() {
msec += 1;
if (msec == 60) {
sec += 1;
msec = 00;
if (sec == 60) {
sec = 00;
min += 1;
if (sec % 2 == 0) {
alert("Pair");
}
}
}
document.getElementById("timer").innerHTML = min + ":" + sec + ":" + msec;
}
}, 3000); //3000 value could be change
Its like i have a certain amount of time suppose 5 minutes or 300 seconds
i want the timer to be started after 300 seconds and keep on going
Change the outer setInterval()
to setTimeout()
. The outer timeout only has run one time per your question. That is what setTimeout()
is designed to do.