Workshop › Blackjack › Step 17 of 22

Blackjack!

What we are doing

An ace and a ten-card as your first two cards is a "blackjack", the best hand. It ends the round at once and pays two and a half times the bet. If the dealer has one instead, you lose at once; if both do, it's a push.

```js
const isBlackjack = (hand) => hand.length === 2 && handValue(hand) === 21

  if (isBlackjack(player) || isBlackjack(dealer)) finish()

  if (isBlackjack(player) && isBlackjack(dealer)) [message, paid] = ['Both blackjack: push', bet]
  else if (isBlackjack(player)) [message, paid] = ['Blackjack!', bet * 2.5]
  else if (isBlackjack(dealer)) message = 'Dealer blackjack'
  else if (p > 21) message = 'Bust!'
```

What it means

Your turn

  1. Above deal, write isBlackjack.
  2. At the end of deal, finish at once on a blackjack.
  3. In finish, put the three blackjack checks first, and turn the bust if into else if.

Skills: Game states

All steps

  1. Cards
  2. A deck
  3. Shuffle
  4. Deal
  5. Cards on the table
  6. Card faces
  7. Keep drawing
  8. What is a hand worth?
  9. Aces: 11 or 1
  10. Hit: one more card
  11. Stand
  12. The hidden card
  13. Chips
  14. Who wins?
  15. The dealer's turn
  16. The next round
  17. Blackjack!
  18. Your record
  19. Double down
  20. Long hands fit
  21. Buttons
  22. Build it yourself: six decks