Pergunta

I was wondering how I make a countdown timer. I have a puzzle app, and one of the puzzles are quick math. It shows a math question in a prompt, but I wanted to put a timer on it before it moves on to the next question. How would I do this?

Foi útil?

Solução

You can try somethink like this, and make o popup for asking user, simple example on fiddle

(function () {
   var timeToWaitInSeconds = 10;

    function countdown(){
    console.log(timeToWaitInSeconds);
    timeToWaitInSeconds -= 1;

        if (timeToWaitInSeconds>0){
            setTimeout(countdown,1000);
        }
    }

    setTimeout(countdown,1000);
}());
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top