Workshop › Minesweeper › Step 13 of 26
Opening a mine loses the game: lose() sets state to 'lost' and opens every mine. After that, clicks do nothing.
```js
if (start.mine) {
lose()
return
}
start.revealed = true
}
function lose() {
state = 'lost'
for (const cell of grid.flat()) if (cell.mine) cell.revealed = true
}
canvas.addEventListener('click', (event) => {
if (state === 'lost') return
```reveal, a mine calls lose() and stops there.lose opens every mine cell.reveal, above start.revealed = true, write the if (start.mine) block.function cellAt, write lose and leave an empty line.if (state === 'lost') return line at the top. Press Run.Skills: Game states
← Click to open Show the mines →