Java Reference

In-Depth Information

}

});

this.roll = function() {

return Math.floor(sides * Math.random() + 1)

}

}

The number of sides can now be assigned in the usual way, but it will act a little differently:

var yellow = new Dice(6);

yellow.sides;

<< "This dice has 6 sides"

yellow.sides = 10;

<< 10

yellow.sides;

<< "This dice has 10 sides"

yellow.sides = 0;

<< Error: "The number of sides must be positive"