0

If you set the variable interval globally, it works normally.

But I want to save the variable interval inside stopWatch() and then call the interval value with hiddenPopUp().

The code below doesn't seem to be able to return an interval...

function stopGame() {
  hiddenPopUp(stopWatch);
}

// let interval;
function stopWatch() {
  let interval = setInterval(() => {
    if (timeStart < 0) {
      clearInterval(interval);
      return;
    } else {
      time(timeStart);
    }
  }, 1000);
  return interval;
}

function hiddenPopUp(interval) {
  clearInterval(interval);
}
junior
  • 1
  • 1) You aren't calling `stopWatch`. 2) Even if you did, all you'd do is create the interval and immediately cancel it – Phil Feb 22 '22 at 04:41

0 Answers0