Answered! Download Dice.js to your 111/p5/folder. A) Complete the rollNDice() method. It should roll N dice and return an array representing the rolls…

var Dice sides 6, current DiceRollsArray: default Image Path: images /3d dice. png, rollDie: function return Math. floor (Math. random this. sides) 1; rollNDice: function n sumNDice: function diceAry max Roll: function (diceAry) t is AllOfAKind: function (diceAry) get Dice Image Path: function (p) return images/red dice p .png3. [20 pts] 111/p5/Dice.js.

Download Dice.js to your 111/p5/folder.

Don't use plagiarized sources. Get Your Custom Essay on
Answered! Download Dice.js to your 111/p5/folder. A) Complete the rollNDice() method. It should roll N dice and return an array representing the rolls…
GET AN ESSAY WRITTEN FOR YOU FROM AS LOW AS $13/PAGE
Order Essay

A) Complete the rollNDice() method. It should roll N dice and return an array representing the rolls:

Dice.rollNDice(6) => [x,x,x,x,x,x] Dice.rollNDice(3) => [x,x,x]

B) Complete the sumNDice() method:

Dice.sumNDice([1,2,3,4]) => 10 Dice.sumNDice([2,3]) => 5 Dice.sumNDice([]) => 0

C) Complete the maxRoll() function: Dice.maxRoll([1,2,3,4]) => 4

D) Complete the isAllOfAKind() function:

Dice.isAllOfAKind([2,2,2,2]) => true Dice.isAllOfAKind([2,2,2,1]) => false

Expert Answer

 var Dice = {

   sides: 6,
currentDiceRollsArray: [],
defaultImagePath: “images/3d_dice.png”,

rollDie: function() {
return Math.floor(Math.random() * this.sides) + 1;
},

rollNDice: function(n) {
results = [];
for(var i=0; i<n; i++) {
results.push(this.rollDie());
}
return results;
},

sumNDice: function(diceAry) {
var sum = 0;
for(var i=0; i< diceAry.length; i++) {
sum += diceAry[i];
}
return sum;
},

maxRoll: function(diceAry) {
var max = 0;
for(var i=0; i< diceAry.length; i++) {
if(diceAry[i] > max) {
max = diceAry[i];
}
}
return max;
},

isAllOfAKind: function(diceAry) {
if(diceAry.length <= 1) {
return true;
}
var value = diceAry[0];

for(var i=1; i< diceAry.length; i++) {
if(diceAry[i] != value) {
return false;
}
}
return true;
},

getDiceImagePath: function(p) {
return “images/red_dice” + p + “.png”
}
}

Answered! Download Dice.js to your 111/p5/folder. A) Complete the rollNDice() method. It should roll N dice and return an array representing the rolls... 1

Still stressed from student homework?
Get quality assistance from academic writers!