Workshop › Endless Runner › Step 5 of 19
A jump is just an upward speed: Space or the up arrow sets vy to -11, and gravity does the rest, slowing the rise
and bringing the runner back down.
```js
const JUMP = -11 // speed at the start of a jump (negative = up)
function jump() {
if (onGround()) runner.vy = JUMP
}
document.addEventListener('keydown', (event) => {
if ((event.key === ' ' || event.key === 'ArrowUp') && !event.repeat) jump()
})
```JUMP is negative because up is negative on the canvas.jump only works on the ground, so there is no jumping in mid-air.event.repeat is true for the automatic repeats of a held key; ignoring them means one press, one jump.GRAVITY, write JUMP.onGround, write jump and the keydown listener.Skills: Keyboard and mouse input, Velocity and gravity