Encountering an issue where player[0].pHand is being modified while updating player[1].pHand (where pHand is an array containing objects).
for(var j = 0; j < 2; j++){
console.log(cardDeck[deckCounter]);
player[0].pHand[j] = cardDeck[deckCounter];
player[0].cardNumber ++;
console.log(player[0].pHand[j]);
deckCounter ++;
}
for(var k = 0; k < 2; k++){
console.log(cardDeck[deckCounter]);
player[1].pHand[k] = cardDeck[deckCounter];
player[1].cardNumber ++;
console.log(player[1].pHand[k]);
console.log(player[0].pHand[k]);
deckCounter ++;
}
Tweaked the code slightly for clarity, having a loop for the player index instead of two separate loops. However, the issue persists with the final set of cards assigned to each player object. The console logs typically show:
Card {suit: "Heart", faceValue: "10", value: 10, played: false, img: "10Heart.png"…}
Card {suit: "Heart", faceValue: "10", value: 10, played: false, img: "10Heart.png"…}
Card {suit: "Heart", faceValue: "3", value: 3, played: false, img: "3Heart.png"…}
Card {suit: "Heart", faceValue: "3", value: 3, played: false, img: "3Heart.png"…}
Card {suit: "Spade", faceValue: "J", value: 10, played: false, img: "JSpade.png"…}
Card {suit: "Spade", faceValue: "J", value: 10, played: false, img: "JSpade.png"…}
Card {suit: "Spade", faceValue: "J", value: 10, played: false, img: "JSpade.png"…}
Card {suit: "Spade", faceValue: "K", value: 10, played: false, img: "KSpade.png"…}
Help or insights would be greatly appreciated :)