Workshop › Minesweeper › Step 11 of 26
An open cell shows how many mines are around it, unless it is 0. Each number has its own colour (1 blue, 2 green, 3 red...), so experienced players read the board at a glance; a lookup list keeps it to one line.
```js
const NUMBER_COLORS = [null, '#2563eb', '#16a34a', '#dc2626', '#7c3aed', '#b45309', '#0891b2', '#111827', '#6b7280']
ctx.font = 'bold 22px sans-serif'
ctx.textAlign = 'center'
ctx.textBaseline = 'middle'
if (cell.count > 0) {
ctx.fillStyle = NUMBER_COLORS[cell.count]
ctx.fillText(String(cell.count), x + CELL / 2, y + CELL / 2 + 1)
}
```NUMBER_COLORS[n] is the colour of the number n. Index 0 is null because 0 is never written.String(count) turns the number into text for fillText.const MINES = 10, write NUMBER_COLORS.draw, above the for loop, write the three text settings.if (cell.revealed) block, under its fillRect, write the if (cell.count > 0) block. Press Run.Skills: Drawing on a canvas
← Open cells look different Click to open →