- 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++) {
console.log(players[i]);
}
};
runGame(diceNumber, cats);
Result
Goalscompleted
- Inside the loop in the body of the function, remove element console log.
- Within the loop, declare variable
throwResult
, which contains the result of one rollmuffin.throwDice(quantity, quantity * 6);
. - Increase the number of roll points for the current player
players[i].points += throwResult;
. - Log in the console the player’s name and the number of their game points
players[i].name + ' rolled ' + players[i].points
.
Comments