Workshop › 2048 › Step 13 of 26
A table turns arrow keys into directions. On a key press we move and then redraw: this game has no loop, the screen changes only when something happens.
```js
const directions = { ArrowLeft: 'left' }
document.addEventListener('keydown', (event) => {
const direction = directions[event.key]
if (direction) {
event.preventDefault()
move(direction)
}
draw()
})
```directions[event.key] is the direction for the key, or undefined for other keys.preventDefault() stops the arrow keys from scrolling the page.draw() repaints after every key.Write the table and the listener above function cellX(col) {, with an empty line after them.
Skills: Keyboard and mouse input
← Move left Only real moves count →