0
votes

I am writing a quiz style application where each question has a countdown timer running. At the end of the countdown the application moves on to the next question. However, on answering the question the timer is supposed to reset. It does not do this and instead creates a new timer, so once the first timer reaches zero it moves on to the next question, which it shouldn't do. I am using the countdown timer from http://www.gieson.com/Library/projects/utilities/countdown/ and my code is as follows:

<script type="text/javascript">
    window.countdown = '';

    function resetTimer()
    {
        window.countdown = new Countdown({ 
            time: 30,
            inline: true,
            rangeHi  : "minute",
            target: "timer",
            width: 50,
            height: 30,
            onComplete : skipQuestion
         });
    }
</script>

Everytime a question is answered (or when the timer runs out and skipQuestion() is called), I call the function resetTimer(). My javasscript is not that great, so instead of trying to reach the developer of the countdown timer, I was hoping that the vast collection of knowledgeable people on here might give me an indication of how to get this working.

Thank you in advance.

2

2 Answers

0
votes

You should call

window.clearInterval(window.countdown);

to stop the running timer. Your code creates a new time anytime you call resetTimer(), so your function should be called createTimer();

0
votes

I found the solution. Simply calling window.countdown.init() resets the timer.