Created
March 9, 2012 22:37
-
-
Save rocktronica/2009078 to your computer and use it in GitHub Desktop.
coinflip()
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
var results = { heads: 0, tails: 0, total: 0 }; | |
function coinflip() { | |
var heads = !!Math.round(Math.random()); | |
if (heads) { | |
results.heads++; | |
} else { | |
results.tails++; | |
}; | |
results.total++; | |
console.log("Heads: " + Math.round(results.heads / results.total * 100) + "%; Tails: " + Math.round(results.tails / results.total * 100) + "%; Flips: " + results.total); | |
if (results.total >= 100) { clearInterval(flipping); } | |
} | |
var flipping = setInterval(coinflip, 25); | |
// will stop at 100 flips. to stop manually... | |
// clearInterval(flipping); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment