Skip to content

Instantly share code, notes, and snippets.

@keithgreer
Last active April 11, 2018 13:55
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 keithgreer/40426ea8c0888840731a3272cc70df2b to your computer and use it in GitHub Desktop.
Save keithgreer/40426ea8c0888840731a3272cc70df2b to your computer and use it in GitHub Desktop.
Logging at random intervals in JavaScript
<!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