Countdown in JavaScript
Dec 12, 2012
So when the user inputs the incorrect answer, the professor I'm building this for wants Storyline to pause for 30 min so they can review the reading (for sanity's sake, I have this at 10sec while testing). Since 30 minutes is a long time to go with the page paused, I made a layer that tells the user they should be reading, and I would like it to have a countdown so they know how long they have until they can continue. For that I have a bit of JavaScript written, however this isn't executing the way I want it to. For some reason it waits 10 seconds and THEN shows the layer, as opposed to showing the layer and seeing the variable adjust on that layer. I've tried having the "Execute JavaScript" trigger after the show layer trigger, and also at the start of the timeline on the layer I want it to execute on. Both do the weird wait-10-second thing.
Below is the code. I haven't been writing in JavaScript long, so it can easily be an error in the code. Please note that in Storyline, I have my seconds and minutes variables set to start at 100 so I could be sure that when I saw 0 minutes 0 sec, that means the seconds and minute variables DID in fact change.
Thanks so much!
Katie
var time = 10;
var player = GetPlayer();
var ONE_SEC = 1000;
player.SetVar("screen", "about to execute main");
main();
player.SetVar("screen", "done with main");
function pausecomp(ms) {
ms += new Date().getTime();
while (new Date() < ms) {}
}
function timer(num) {
var minutes = ~~(num / 60);
var seconds = (num - (minutes * 60));
player.SetVar("min", minutes);
player.SetVar("sec", seconds);
}
function main() {
player.SetVar("screen", "in main");
for (var i=0; i <= time; i++) {
player.SetVar("screen", "in for");
pausecomp(ONE_SEC);
timer(time-i);
}
player.SetVar("timesup", true);
}
9 Replies
I wouldnt use javascript to achieve this, it is relatively easy to use layers to create a countdown and this negate this issue of javascript not working in some browsers and on the iPad
This will ultimately be a 30 minute countdown, would using layers still be an efficient solution? If so, please elaborate.
that is fine you can build it into a slide master so would work on any slide, I posted a demo somewhere that did this(not on the master)
You would set the time in the variables and let it run
Thanks!
Hi Katie,
I found this for you.
http://community.articulate.com/downloads/p/845.aspx
hope it helps
Geert
Javascript might be the only option for content exported out as HTML5. the counter only updates when you navigate between slides, and as there is no playhead firing off, the time is not updated correctly.
I ended up using layers (two that run one second long and each point at each other) to do the timer. We also got the instructor to shorten the 30 min time to 1 minute.
There should be no reason why it wouldnt update, a layer is opening each second which would trigger the update
aha! the quiz works in HTML5! The countdown story file I found in http://community.articulate.com/forums/p/17107/98267.aspx , not so much.
This discussion is closed. You can start a new discussion or contact Articulate Support.