Workshop › Space Invaders-style › Step 4 of 21
The ship must not leave the screen. After moving, its x is kept between 0 and the canvas width minus the ship's width.
```js
ship.x = Math.max(0, Math.min(canvas.width - SHIP_W, ship.x))
```Math.min(canvas.width - SHIP_W, x) stops it at the right edge, Math.max(0, ...) at the left edge.At the end of update, write the line.
Skills: Game states