ES6
Created
November 25, 2020 22:57
-
-
Save luisenriquecorona/34275d53d23766c087a853722048ea5c to your computer and use it in GitHub Desktop.
IntervalId.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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