Workshop › Blackjack › Step 10 of 22
On your turn you may ask for another card: that is a "hit". phase remembers whose turn it is. Every key goes through a
small table to a button name, and press does what the button says. H is Hit; the other buttons come in the next steps.
```js
let phase // 'player' (your turn), 'dealer' (the dealer draws) or 'done' (the round is over)
phase = 'player'
}
function hit() {
if (phase !== 'player') return
player.push(nextCard())
}
function press(button) {
if (button === 'Hit') hit()
}
document.addEventListener('keydown', (event) => {
const keys = { h: 'Hit', s: 'Stand', d: 'Double', n: 'Deal', ' ': 'Deal' }
const button = keys[event.key.toLowerCase()]
if (!button) return
event.preventDefault()
press(button)
})
```phase = 'player'.hit does nothing when it is not your turn.toLowerCase makes H and h the same; keys not in the table are ignored.press, so keys and buttons can't disagree.dealer, write phase with its comment.deal, start your turn; under deal, write hit.drawCard, write press and the key listener.Skills: Keyboard and mouse input, Game states