Skip to content

Commit 57519ec

Browse files
committed
Splitting up the Die rolling app to use exports
1 parent 594d1c0 commit 57519ec

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

05_dice.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Object Literal For A Dice
2+
var die = {
3+
size: 6,
4+
totalRolls: 0,
5+
roll: function () {
6+
// this is referring to the object itself
7+
var result = Math.ceil(this.size * Math.random());
8+
this.totalRolls += 1;
9+
return result;
10+
}
11+
};
12+
13+
exports.die = die;

05_program.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Program to use dice.js
2+
var dice = require("./05_dice");
3+
var die = dice.die
4+
5+
die.size = 10;
6+
console.log(die.roll());
7+
console.log(die.roll());
8+
console.log(die.roll());
9+
console.log("Total rolls " + die.totalRolls);

0 commit comments

Comments
 (0)