- script.js
JavaScript
var diceNumber = 2;
var firstCat = {
name: 'Muffin',
points: 0
};
var secondCat = {
name: 'Rudolph',
points: 0
};
var cats = [firstCat, secondCat];
var runGame = function (quantity, players) {
for (var i = 0; i < players.length; i++) {
var throwResult = muffin.throwDice(quantity, quantity * 6);
players[i].points += throwResult;
console.log(players[i].name + ' rolled ' + players[i].points);
}
return players;
};
cats = runGame(diceNumber, cats);
console.log(cats);
Result
Goalscompleted
- At the beginning of the code, in front of the player objects, create an object
gameRules
with propertiesdiceNumber: 2
andmaxAttempts: 3
. - In
runGame
function declaration, rename parameterquantity
inrules
. - In
runGame
function call, replace argumentdiceNumber
withgameRules
. - In the body of the
runGame
function, replace the reference to parameterquantity
with accessing propertydiceNumber
of parameterrules
. - Delete the
diceNumber
variable.
Comments