Workshop › Frogger-style Crossing › Step 11 of 22
After a game over, Space starts a new game. All the starting values go into reset, which also runs once at the start.
```js
let frog
let lives
let state // 'playing' or 'over'
function reset() {
lives = 3
state = 'playing'
for (const lane of LANES) lane.offset = 0
newFrog()
}
if (event.key === ' ' && state === 'over') reset()
reset()
```reset gives them their starting values, puts the traffic back
and makes a new frog.let frog = ... to the offset line with plain declarations.newFrog, write reset.keydown, add the Space line; call reset() above requestAnimationFrame(loop) at the bottom.Skills: Game states, Functions
← Three lives Tap to play again →