Skip to content

Instantly share code, notes, and snippets.

@luisenriquecorona
Created November 25, 2020 22:57
Show Gist options
  • Save luisenriquecorona/34275d53d23766c087a853722048ea5c to your computer and use it in GitHub Desktop.
Save luisenriquecorona/34275d53d23766c087a853722048ea5c to your computer and use it in GitHub Desktop.
IntervalId.js
let num = 0, intervalId = null;
let max = 10;
let incrementNumber = function() {
num++;
// if the max has been reached, cancel all pending executions
if (num == max) {
clearInterval(intervalId);
console.log("Done");
}
}
intervalId = setInterval(incrementNumber, 500);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment