0

i'm making a speed typing game where a 60 second countdown starts at user input. I've heard setInterval is inaccurate, should i be using the newDate method? In advance, thanks ; )

let has_started = false;

//starte nedtelling
function startTimer() {
  if (!has_started) {
    has_started = true;
  }

  //Definerer tidsgrense
  let tidsgrense = 60;
  let nedtelling = setInterval(function () {
    tidsgrense--;
    document.getElementById('timer').textContent = tidsgrense;

    if (tidsgrense === 0) clearInterval(nedtelling);
    timer = window.setTimeout(() => {
      alert(`60 sekunder har gått, poengsummen din ble poeng`);
      window.location.reload();
    }, 60000);
  }, 1000);
}
 <textarea
        oninput="sjekkSvar();startTimer()"
        ;
        id="inputFelt"
        autofocus
      ></textarea>

0 Answers0