Workshop › Snake › Step 24 of 28
To play again we must put every value back to its start. We gather all the starting values in reset() and call it
once at the start.
```js
let snake
let dir
let nextDir
let food
let score
let gameOver
let last = 0
function reset() {
snake = [
{ x: 5, y: 5 },
{ x: 4, y: 5 },
{ x: 3, y: 5 },
]
dir = { x: 1, y: 0 }
nextDir = dir
score = 0
gameOver = false
placeFood()
}
reset()
requestAnimationFrame(loop)
```reset() gives them their starting values and places the first food.placeFood() call is replaced by reset() at the bottom, before the loop starts.let snake = [ to let gameOver = false) with the empty declarations and reset.placeFood() call under placeFood.reset() right before requestAnimationFrame(loop) at the bottom.Skills: Game states, Functions
← Show the score Play again with Space →