Created
August 23, 2013 11:45
-
-
Save sanandnarayan/6318453 to your computer and use it in GitHub Desktop.
Wait and Print
This file contains 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
// 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