Workshop › Pong › Step 21 of 26
A reset function gathers everything a new match needs: paddles in place, scores at 0, playing, first serve. Space
calls it after a match.
```js
let left
let right
let ball
let state // 'playing' or 'over'
function reset() {
left = { x: 20, y: 160, score: 0 }
right = { x: canvas.width - 20 - PADDLE_W, y: 160, score: 0 }
state = 'playing'
serve(1)
}
if (event.key === ' ' && state === 'over') reset()
reset()
```reset gives them their starting values.reset() at the bottom starts the first match (it replaces the old serve(1)).left to state) with the plain declarations, and write reset under const keys = {}.keydown listener, add the Space line.serve(1) at the bottom with reset().Skills: Game states, Functions
← Who won? Aim with the paddle →