I am trying to convert the value of the 2 cards in each Hand array to points, so that I can tally them up and compare the two.
Currently, it says my playerPoints is NaN, so my issue is in the for-of loop or my playerHand.point.
for (let i = 0; i < 2; i++) {
playerHand.push(dealRandomCard());
dealerHand.push(dealRandomCard());
}
// console.log(playerHand);
// console.log(dealerHand);
let playerPoints = 0,
dealerPoints = 0;
for (point of playerHand) {
playerPoints += playerHand.point;
}
console.log(playerPoints);
REVISED - WORKING CODE - Thanks to Nina
for (let { points } of playerHand {
playerPoints += points
}
Assuming the objects of a last question of OP of the same kind, it should be points
in stead of point
.
Beside this, you need to take the points
property by using a destructuring assignment
for (let { points } of playerHand) {
playerPoints += points;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.