$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · hard · #79

Which fix removes the bug?

let timer;
function poll() {
  timer = setInterval(fetchNow, 1000);
}
poll();
poll();
  1. Call clearInterval(timer) before setting
  2. Call clearTimeout(timer) before setting
  3. Change setInterval to setTimeout here
  4. Declare timer inside the poll function
The second call orphans the first interval, which keeps firing forever; clear it first.
Play Problem Solving ▸