Javascript Timer
Hi all. I have a java script timer that executes on a slide. When I replay the screen, I need it to reset the timer. What happens right now, is that it seems to add a new timer along with the previous timer, and they interfere with each other, given times from each timer back and forth. Is there a way that I can clear the previous timer out when I replay this screen? Here is the javascript that I am executing on the slide:
var player=GetPlayer();
function countdown( elementName, minutes, seconds )
{
var endTime, hours, mins, msLeft, msTotal, time;
function twoDigits( n )
{
return (n <= 9 ? "0" + n : n);
}
function updateTimer()
{
msLeft = endTime - (+new Date);
if ( msLeft < 1000 ) {
player.SetVar("timer", "0:00");
} else {
time = new Date( msLeft );
hours = time.getUTCHours();
mins = time.getUTCMinutes();
player.SetVar("timer", (hours ? hours + ':' + twoDigits( mins ) : mins) + ':' + twoDigits( time.getUTCSeconds() ));
setTimeout( updateTimer, time.getUTCMilliseconds() + 500 );
}
}
endTime = (+new Date) + 1000 * (60*minutes + seconds) + 500;
msTotal = endTime - (+new Date);
updateTimer();
}
countdown( "timer", 4, 00 );