Workshop › Blackjack › Step 8 of 22
Number cards are worth their number, J, Q and K are worth 10, and an ace is worth 11 (for now). handValue adds up a
hand; the totals are shown above both hands. We also count the aces: the next step needs that.
```js
function handValue(hand) {
let total = 0
let aces = 0
for (const { rank } of hand) {
if (rank === 'A') {
total += 11
aces += 1
} else total += ['J', 'Q', 'K'].includes(rank) ? 10 : Number(rank)
}
return total
}
ctx.fillStyle = 'white'
ctx.font = 'bold 16px sans-serif'
ctx.textAlign = 'left'
ctx.fillText('Dealer ' + handValue(dealer), 20, DEALER_Y - 10)
ctx.fillText('You ' + handValue(player), 20, PLAYER_Y - 10)
```for (const { rank } of hand) takes just the rank of each card.['J', 'Q', 'K'].includes(rank) asks whether the rank is a face card; Number('7') turns the text into 7.deal, write handValue.draw, write both totals.Skills: Functions, Loops
← Keep drawing Aces: 11 or 1 →