Workshop › Sudoku › Step 14 of 28
The puzzle is solved when every cell is filled and nothing clashes. After each digit we check; once won, no more digits can be written.
```js
let won
won = false
function checkWin() {
for (let r = 0; r < 9; r++) for (let c = 0; c < 9; c++) if (grid[r][c] === 0 || conflict(r, c)) return
won = true
}
function enter(d) {
if (won || given[selected.r][selected.c]) return
grid[selected.r][selected.c] = d
checkWin()
}
```checkWin looks at all 81 cells and stops at the first empty or clashing one; if none, the puzzle is won.for loops and an if can be written on one line when each body is a single statement.let selected, write let won; in reset, set it to false.enter, write checkWin; in enter, add won || and call checkWin().Skills: Game states