Created
December 3, 2013 21:38
-
-
Save joeytrapp/7777905 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
battle = (function() { | |
function completelyAccurateBattleCalculator() { | |
return Math.floor((Math.random()*10)+1); | |
} | |
function predictWinner(i) { | |
if (i >= 1 && i < 5) { | |
return 'goku'; | |
} else if (i > 5 && i <= 10) { | |
return 'jl'; | |
} else { | |
return 'suckit'; | |
} | |
} | |
function battle() { | |
var results = {}, key, buf = ''; | |
for (var i = 0, len = 1000; i < len; i++) { | |
key = predictWinner(completelyAccurateBattleCalculator()); | |
results[key] = results[key] === undefined ? 1 : results[key] + 1; | |
} | |
buf += "Justice League won " + results['jl'] + " times.\n"; | |
buf += "Goku won " + results['goku'] + " times.\n"; | |
buf += "And John can suck it " + results['suckit'] + " times.\n"; | |
console.log(buf); | |
} | |
return battle; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment