0

When I run the counter for first the seconds are counting correctly(1000miliseconds). However, when I reset the counter to 0 and start the counter again, I have notice that the counter speed is increased. It' doesn't make sense, since the interval is constant of 1000.

What can cause such behavior? Thank you in advance.

function StartCounter() {
  setInterval(IncreaseSeconds, 1000);
}

function IncreaseSeconds() {
  let seconds = parseInt(document.getElementById("setter-post-counter").innerText);
  document.getElementById("setter-post-counter").innerText = seconds + 1;
}

function Reset() {
  document.getElementById("setter-post-counter").innerText = 0;
}
<div class="onerow">
  <p id="setter-post-counter">0</p><span>seconds</span></div>

<button onClick="StartCounter()">Start</button>
<button onClick="Reset()">Reset</button>
Michael M.
  • 10,486
  • 9
  • 18
  • 34
Kate
  • 19
  • 4

0 Answers0