Workshop › Conway's Game of Life › Step 19 of 32
Soon there will be keys and on-screen buttons doing the same things. So every action goes through one function,
press(button): 'Play' starts or stops the world, 'Step' stops it and advances one generation.
```js
function press(button) {
if (button === 'Play') playing = !playing
else if (button === 'Step') {
playing = false
step()
}
}
```button is the name of the button pressed.!playing is the opposite of playing, so 'Play' flips it on and off.else if checks the next case only when the first one was not true.Write press above the keydown listener, with an empty line between them.
Skills: Functions, Game states
← Running or not Space to play, N to step →