I'm currently developing a blackjack game using Javascript, and I need to create objects for each card so that multiple cards add up to 10. My challenge lies in adding the values of these objects together when they are stored in an array. Here is the relevant code snippet:
var dealerArr = [];
var playerArr = [];
var dealerTotal = 0;
var playerTotal = 0;
var two = {
value: 2
}
var three = {
value: 3
}
// The list continues with values for each card
function calcTotal(arr) {
var sum = 0;
for (var object of arr) {
sum += object.value;
}
return sum;
}
while (calcTotal(dealerArr) < 17) {
// Code logic for selecting random cards and pushing them into the dealerArr
}