- 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;
};
var getWinners = function (players) {
var winners = [];
return winners;
};
cats = runGame(gameRules, cats);
console.log(cats);
var tops = getWinners(cats);
console.log(tops);
Result
Goalscompleted
- In the body of the
getWinners
function, after the declaration of variablewinners
, write a loop that increases variablei
from0
up to the length of arrayplayers
(not including this value).i
must increase by one after each iteration. - Inside the loop, create variable
currentPlayer
, which is equal to the current element of the array. - Log
currentPlayer
variable in the console.
Comments