0

Here is my JavaScript code. I want to avoid resetting timer when the page is refreshed.

const startingMinutes = 1;
let time = startingMinutes * 60;

const countdownEl = document.getElementById('countdown');

setInterval(updateCountDown, 1000);

    function updateCountDown() {
        const minutes = Math.floor(time/60);
        let seconds = time % 60;
    
        countdownEl.innerHTML = `${minutes}: ${seconds}`;
    
        if (time>0) {
            time--;
        }
    }
  • save the data to LocalStorage: https://stackoverflow.com/questions/56805408/localstorage-and-setinterval-with-multiple-tabs – Oleg May 01 '22 at 07:13
  • Here is a working example: https://jsfiddle.net/tLajobq1/ – Yogi May 01 '22 at 08:18
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. – Community May 01 '22 at 13:01

1 Answers1

0

Store the current counter variable in local storage.

Hope this helps.

Friday Ameh
  • 1,664
  • 1
  • 10
  • 15