Workshop › Pong › Step 9 of 26
Every game has two jobs: update (change the state) and draw (show it). update moves each paddle 6 pixels per
frame while its keys are held: W/S for the left paddle, the arrows for the right one.
```js
const PADDLE_SPEED = 6
function update() {
if (keys.w) left.y -= PADDLE_SPEED
if (keys.s) left.y += PADDLE_SPEED
if (keys.ArrowUp) right.y -= PADDLE_SPEED
if (keys.ArrowDown) right.y += PADDLE_SPEED
}
function loop() {
update()
draw()
```if checks one held key; -= moves up (y gets smaller), += moves down.loop calls update() before draw(), so each frame first changes the state, then shows it.PADDLE_H, write PADDLE_SPEED.function draw, write update and an empty line.loop, write update() above draw().Skills: Keyboard and mouse input, Game states
← Remember held keys Stay on the court →