Skip to content

Instantly share code, notes, and snippets.

@joeytrapp
Created December 3, 2013 21:38
Show Gist options
  • Save joeytrapp/7777905 to your computer and use it in GitHub Desktop.
Save joeytrapp/7777905 to your computer and use it in GitHub Desktop.
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