Forum Discussion
JavaScript Countdown Timer
Hi there, I made a few changes to your existing code. I set the countdown duration to 5 minutes (300 seconds) by assigning count
the value of 300.
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;
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.
- LoriDresner2 years agoCommunity Member
This works perfectly! Thank you!
- SandeepGadam2 years agoCommunity Member
You're welcome!!