Workshop › Conway's Game of Life › Step 24 of 32
Now a click (or a tap) flips the cell under the pointer: dead becomes alive, alive becomes dead.
```js
canvas.addEventListener('pointerdown', (event) => {
const cell = cellAt(toCanvas(event))
if (!cell) return
grid[cell.r][cell.c] = grid[cell.r][cell.c] ? 0 : 1
})
```pointerdown fires when a mouse button or a finger goes down on the canvas.cellAt(toCanvas(event)) turns the event into a cell; off the grid we return and do nothing.1 becomes 0, 0 becomes 1.Write the listener under cellAt, above function update() {, with an empty line after it.
Skills: Keyboard and mouse input
← Which cell? Paint or erase? →