Forum Discussion
JavaScript CountDown Timer Not Working in a Browser
It’s a simple explanation. The previous setTimeout chain is still active when you return to the slide, and a new startTimer() is triggered again. This leaves you with multiple timers running simultaneously. One of them reaches 0 earlier than expected, which sets the timerFinished variable to true, causing the message to appear prematurely.
The solution is to ensure that only one timer instance can run at a time and that any previous timers are properly cleared. This prevents the countdown from stacking and guarantees that the timerFinished variable is triggered only once.
I’ve attached two working versions. Both include a JavaScript trigger placed on the Slide Master.
- Version 1 is a plain implementation where all slides start counting down from 5 seconds, similar to your original file.
- Version 2 adds flexibility by introducing a setTimeTo() window function. This allows you to define a different countdown duration per slide if needed.
The main script runs on the Slide Master, and on individual slides you simply execute a JavaScript trigger such as setTimeTo(10) or setTimeTo(15) to set the desired time. Both versions include two Storyline variables: a text variable named timer (referenced in the text box to display the current time) and a Boolean variable named timerFinished, just like in your original file.