سؤال

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?

هل كانت مفيدة؟

المحلول

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);
}());
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top