Forum Discussion
JavaScript Countdown Timer
Hello Kev, in the above code you modify the "timer()" function as follows:
function zeros(i) {
if (i < 10) {
i = "0" + i;
}
return i;
}
var counter = setInterval(timer, 1000);
var fin = "Done";
var player = GetPlayer();
var count = player.GetVar("Countdown_Duration");
function timer() {
count = count - 1;
if (count < 0) {
count = 0; // Set the countdown to 0 when it goes below 0
}
minutes = zeros(Math.floor(count / 60));
seconds = zeros(count % 60);
if (count <= 0) {
player.SetVar("Countdown_Finished", fin);
clearInterval(counter);
return;
}
totalTime = minutes + ':' + seconds;
player.SetVar("Countdown_Display", totalTime);
}
count = 300; // Set the countdown duration to 5 minutes (300 seconds)
minutes = zeros(Math.floor(count / 60));
seconds = zeros(count % 60);
totalTime = minutes + ':' + seconds;
player.SetVar("Countdown_Display", totalTime);
Try this and let me know if this works.