LoriDresner
2 years agoCommunity Member
JavaScript Countdown Timer
Hi all. I need to add a countdown timer to one of my Storyline slides so people don't skip through it too quickly. I already have a JavaScript code I've borrowed from someone for a different project, but it seems that the page I got it from no longer exists, so I cannot figure out how to change it. It is currently set to 35 seconds; how would I change it to 5 minutes? Thanks in advance!
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);
}
if (count < 0) {
clearInterval(counter);
return;
}
totalTime = minutes + ':' + seconds;
player.SetVar("Countdown_Display",totalTime);
}
minutes = zeros(Math.floor(count / 60));
seconds = zeros(count % 60);
if (count == 0){
player.SetVar("Countdown_Finished",fin);
}
if (count < 0) {
clearInterval(counter);
return;
}
totalTime = minutes + ':' + seconds;
player.SetVar("Countdown_Display",totalTime);