Workshop › Snake › Step 10 of 28
The head always moves right because update adds 1 to x. We keep the direction in a variable dir instead,
so it can change.
```js
let dir = { x: 1, y: 0 }
function update() {
head.x += dir.x
head.y += dir.y
}
```dir holds how many cells to move each turn: x: 1, y: 0 is one to the right.update adds dir to the head, so changing dir changes where the snake goes.let head = ... write let dir = { x: 1, y: 0 }.update, replace head.x += 1 with the two lines using dir.Skills: Game states
← Slow it down Steer with the arrow keys →