Workshop › Tic-tac-toe › Step 21 of 33
When the round is over, draw dims the board with a see-through black and writes X wins!, O wins! or
It's a draw in the middle.
```js
if (result) {
ctx.fillStyle = 'rgba(0, 0, 0, 0.55)'
ctx.fillRect(0, 0, canvas.width, canvas.height)
ctx.fillStyle = 'white'
ctx.font = 'bold 28px sans-serif'
ctx.fillText(result === 'draw' ? "It's a draw" : result + ' wins!', canvas.width / 2, 140)
}
}
```if (result) { ... } runs only when the round is over.rgba(0, 0, 0, 0.55) is black at 55% strength: the marks still show through.result + ' wins!' glues two strings together: 'X wins!'."It's a draw" uses double quotes because it contains a '.In draw, after the forEach block's }) and before the function's last }, leave an empty line and write the
if block. Run and win a round.
Skills: Drawing on a canvas, Game states
← The round ends Light up the winning line →