0

I have a timer of 30 seconds in a page. I used the setInterval function to make it count to 0 but when i refresh my page the timer appears 1 sec after the loading (because of the delay of 1000ms i suppose). I would like to know if there is something to do to make it appears instantly. Here is the code :

    let response = await getDataAsync();
    const TIMER = (function timing(){
        let sec = 30;
        timer = setInterval(() => {
           sec = sec < 10 ? "0" + sec : sec;
            timerElement.innerHTML = '00:'+sec;
            sec = sec <= 0 ? 0: sec - 1
            if (sec === 0) {
                iteration_question++;
                localStorage.setItem('iteration_question', (iteration_question.toString()));
                setTimeout(document.location.reload(true), 2000);
            }
        }, 1000)
    })()

Thank you.

0 Answers0