so I have been staring at this issue for some time now and I cannot understand what is going wrong. I am trying to create the game Yahtzee, and I have a function that will randomly generate the 5 dice. This function is also reused when the user wishes to roll again. I pass in an array of objects, each object has a number property representing what the user rolled. I ran into this issue where the loop I have to generate a new dice set, does not replace the old one. Here is my function code
function roll(theRoll){
diceSet = theRoll;
console.log("before")
console.log(diceSet)
for(let i = 0; i < diceSet.length; i++){
if(diceSet[i].isHeld == false){
diceSet[i].number = Math.floor((Math.random() * 6) + 1);
}
document.getElementById("die" + (i + 1) + "Img").src = "img/" + diceSet[i].number + ".png";
}
console.log("After")
console.log(diceSet)
return theRoll;
}
Now I could be wrong but the code above should work fine but my "diceSet" has the same numbers before and after the loop, but I dont have any clue why the properties are not changing.
Any help would be appreciated thank you