Workshop › Tic-tac-toe › Step 24 of 33
When the round is over, the next click starts a new one instead of playing. We also tell the player so, under the result.
```js
canvas.addEventListener('click', (event) => {
if (result) {
reset()
} else {
// The canvas may be displayed at a different size than its 300×300 pixels, so scale the click.
const rect = canvas.getBoundingClientRect()
const x = (event.clientX - rect.left) * (canvas.width / rect.width)
const y = (event.clientY - rect.top) * (canvas.height / rect.height)
const index = Math.floor(y / CELL) * 3 + Math.floor(x / CELL)
play(index)
}
draw()
})
ctx.font = '14px sans-serif'
ctx.fillText('Click to play again', canvas.width / 2, 172)
```if (result) { reset() } else { ... }: after the round, a click resets; otherwise it plays as before.else means "otherwise". The old lines move inside it, two spaces further in; they do not change otherwise.draw, under the result text.draw() stays outside, so both cases redraw.draw write the small hint under the result.play(index)) in if (result) { reset() } else { ... }.draw, under the result fillText, add the two Click to play again lines.Skills: Keyboard and mouse input, Game states
← A function for a fresh round A computer that picks a cell →