Workshop › Conway's Game of Life › Step 21 of 32
Two more buttons: 'Clear' empties and stops the world (C), 'Random' throws in a new soup (R).
```js
function clear() {
grid = emptyGrid()
generation = 0
playing = false
}
} else if (button === 'Random') randomize()
else if (button === 'Clear') clear()
}
const keys = { ' ': 'Play', n: 'Step', r: 'Random', c: 'Clear' }
```clear puts an empty grid in place, sets the generation to 0 and stops the world.press gets two more cases, and the key table two more keys.randomize, after an empty line, write clear.press, change } after step() to } else if (button === 'Random') randomize() and add the 'Clear' line.r and c to the key table.Skills: Keyboard and mouse input, Game states
← Space to play, N to step Where is the pointer? →