Workshop › Sudoku › Step 11 of 28
Keys 1 to 9 write a digit in the selected cell; 0, Backspace or Delete erase it. The puzzle's own digits cannot be changed.
```js
function enter(d) {
if (given[selected.r][selected.c]) return
grid[selected.r][selected.c] = d
}
} else if (event.key >= '1' && event.key <= '9') enter(Number(event.key))
else if (event.key === '0' || event.key === 'Backspace' || event.key === 'Delete') enter(0)
```enter writes into the selected cell unless it is a given one; writing 0 erases.event.key >= '1' && event.key <= '9' compares texts: a single character between '1' and '9' is a digit key.Number(event.key) turns '7' into 7.reset function, write enter.keydown, write the two else if lines after the arrow block.Skills: Keyboard and mouse input, Game states
← Move with the arrows The three rules in one loop →