Skip to content

Instantly share code, notes, and snippets.

@olimay
Created February 28, 2016 01:26
Show Gist options
  • Save olimay/7b4466f64d6f22119de8 to your computer and use it in GitHub Desktop.
Save olimay/7b4466f64d6f22119de8 to your computer and use it in GitHub Desktop.
Testing utility for jsfr_ex02.1.js : inline HTML version
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
.chart rect {
fill: steelblue;
}
.axis text {
font: 10px sans-serif;
}
.axis path,
.axis line {
fill: none;
stroke: #000;
shape-rendering: crispEdges;
}
.debug p {
font: 10px monospace;
background: #ddd;
}
</style>
</head>
<body>
<script src="jsfr_ex02.1.js"></script>
<script type="text/javascript">
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);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment