- script.js
JavaScript
var gameRules = {
diceNumber: 2,
maxAttempts: 3
};
var firstCat = {
name: 'Muffin',
points: 0
};
var secondCat = {
name: 'Rudolph',
points: 0
};
var cats = [firstCat, secondCat];
var runGame = function (rules, players) {
for (var currentAttempt = 1; currentAttempt <= rules.maxAttempts; currentAttempt++) {
for (var i = 0; i < players.length; i++) {
var throwResult = muffin.throwDice(rules.diceNumber, rules.diceNumber * 6);
players[i].points += throwResult;
console.log(players[i].name + ' rolled ' + players[i].points);
}
}
return players;
};
cats = runGame(gameRules, cats);
console.log(cats);
Result
Goalscompleted
- After the
runGame
function, declare thegetWinners
function parameterplayers
. - In the body of the function, declare empty array
winners
and return it from the function. - In the code of the program, after logging in the console of the
cats
array, create variabletops
and write in it the result of the functiongetWinners(cats)
. - Log variable
tops
in the console.
Comments