Skip to content

Instantly share code, notes, and snippets.

@olimay
Created February 28, 2016 01:23
Show Gist options
  • Save olimay/7aff2ff30805d29ddf0f to your computer and use it in GitHub Desktop.
Save olimay/7aff2ff30805d29ddf0f to your computer and use it in GitHub Desktop.
Testing utility for jsfr_ex02.1.js
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