Workshop › Blackjack › Step 15 of 22

The dealer's turn

What we are doing

The dealer has no choices: below 17 they draw, at 17 or more they stand, and then the round is finished. To make it feel like a real table, each of the dealer's moves waits half a second (30 frames).

```js
const DELAY = 30 // frames between the dealer's cards
let timer

  timer = DELAY

function update() {
  if (phase !== 'dealer') return
  timer -= 1
  if (timer > 0) return
  // The dealer has no choice: draw below 17, stand on 17 or more.
  if (handValue(dealer) < 17) {
    dealer.push(nextCard())
    timer = DELAY
  } else finish()
}

  update()
```

What it means

Your turn

  1. Under BET, write DELAY; under bet, write timer; in stand, set the timer.
  2. Above press, write update.
  3. In loop, call update() before draw().

Skills: Game states, The game loop

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