- 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
catswithfirstCat,secondCatelements before functionrunGame. - Delete parameters
firstPlayerandsecondPlayerin declaration of functionrunGameand instead of them add parameterplayers. - Delete arguments
firstCatandsecondCatin function call and instead of them add argumentcats. - In the body of the
runGamefunction, instead of the entire code, write a loop that increases variableifrom0toplayers.length(not including this value). Value ofimust increase by one after each iteration. - Inside the loop, log in the console the current element of the
playersarray.
Comments