- script.js
JavaScript
var diceNumber = 2;
var firstCat = {
name: 'Muffin',
points: 0
};
var secondCat = {
name: 'Rudolph',
points: 0
};
var runGame = function (quantity, firstPlayer, secondPlayer) {
firstPlayer.points += muffin.throwDice(quantity, quantity * 6);
secondPlayer.points += muffin.throwDice(quantity, quantity * 6);
console.log(firstPlayer.name + ' rolled ' + firstPlayer.points);
console.log(secondPlayer.name + ' rolled ' + secondPlayer.points);
};
runGame(diceNumber, firstCat, secondCat);
Result
Goalscompleted
- Create an array
cats
withfirstCat
,secondCat
elements before functionrunGame
. - Delete parameters
firstPlayer
andsecondPlayer
in declaration of functionrunGame
and instead of them add parameterplayers
. - Delete arguments
firstCat
andsecondCat
in function call and instead of them add argumentcats
. - In the body of the
runGame
function, instead of the entire code, write a loop that increases variablei
from0
toplayers.length
(not including this value). Value ofi
must increase by one after each iteration. - Inside the loop, log in the console the current element of the
players
array.
Comments