Created
February 28, 2016 01:23
-
-
Save olimay/7aff2ff30805d29ddf0f to your computer and use it in GitHub Desktop.
Testing utility for jsfr_ex02.1.js
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
roll = function(x){ return Math.floor(Math.random() * x + 1) }; | |
function Tally(limit){ | |
this.limit = limit; | |
this.rollCounts = []; | |
this.modCounts = {}; | |
this.literateCount = 0; | |
this.getTally = function(){ | |
var charGen = new CharacterGenerator(); | |
for (i = 0; i < limit; i++) { | |
var intRoll = roll(7); | |
var intModifier = charGen.intMod(intRoll); | |
// roll counts | |
if (undefined == this.rollCounts[intRoll]) { | |
this.rollCounts[intRoll] = 1; | |
} | |
else { | |
this.rollCounts[intRoll]++; | |
} | |
// modifier counts | |
if (undefined == this.modCounts[intModifier.toString()]) { | |
this.modCounts[intModifier.toString()] = 1; | |
} | |
else { | |
this.modCounts[intModifier.toString()]++; | |
} | |
// literate counts | |
if (charGen.literate) { this.literateCount++; } | |
} // for | |
}; // this.getTally | |
} | |
console.log("Tally"); | |
var t = new Tally(10000); | |
t.getTally(); | |
console.log(t.rollCounts); | |
console.log(t.modCounts); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment