Skip to content

Instantly share code, notes, and snippets.

@sanandnarayan
Created August 23, 2013 11:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sanandnarayan/6318453 to your computer and use it in GitHub Desktop.
Save sanandnarayan/6318453 to your computer and use it in GitHub Desktop.
Wait and Print
// problem: why does it log out out 1000?
// fix it to log 100, 200, 300, 400, 500 etc
// loops 10 times from 0 - 1000 in increments of 100
for (var i = 0; i < 1000; i += 100) {
waitFor(i, function then() {
console.log(i)
})
}
// this will run a callback function after waiting milliseconds
function waitFor(milliseconds, callback) {
setTimeout(callback, milliseconds)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment