- 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
gameRuleswith propertiesdiceNumber: 2andmaxAttempts: 3. - In
runGamefunction declaration, rename parameterquantityinrules. - In
runGamefunction call, replace argumentdiceNumberwithgameRules. - In the body of the
runGamefunction, replace the reference to parameterquantitywith accessing propertydiceNumberof parameterrules. - Delete the
diceNumbervariable.
Comments