Last active
April 11, 2018 13:55
-
-
Save keithgreer/40426ea8c0888840731a3272cc70df2b to your computer and use it in GitHub Desktop.
Logging at random intervals in JavaScript
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
<!DOCTYPE html> | |
<html> | |
<body> | |
<script> | |
for (i = 0; i < 5; i++) { | |
(function() { | |
var j = i; | |
var x = Math.floor(Math.random() * 20000); | |
setTimeout(function () { | |
// Log Result of i (increment) and x (time) | |
console.log(j+" "+x); | |
}, x); | |
})(); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment