Workshop › Pong › Step 25 of 26
The 2 key switches between playing the computer and playing a friend, and a grey line at the bottom says which mode is on.
```js
if (event.key === '2') twoPlayers = !twoPlayers
ctx.fillStyle = '#888'
ctx.font = '14px sans-serif'
const hint = twoPlayers ? 'Two players · press 2 to play the computer' : 'W/S to move · press 2 for two players'
ctx.fillText(hint, canvas.width / 2, canvas.height - 12)
```!twoPlayers is the opposite: true becomes false and back. This is called toggling.? :.keydown listener, write the '2' line under keys[event.key] = true.draw, after an empty line, write the hint lines.Skills: Keyboard and mouse input
← A computer opponent Build it yourself: a serve pause →