Workshop › Snake › Step 21 of 28
Running into your own body ends the game too. The tail is left out of the check, because it moves away this turn.
```js
const hitSelf = snake.slice(0, -1).some((part) => part.x === head.x && part.y === head.y)
if (hitWall || hitSelf) {
```snake.slice(0, -1) is a copy of the snake without its last part (the tail)..some(...) is true if any of those parts is on the new head's cell.Under hitWall write hitSelf, and change if (hitWall) to if (hitWall || hitSelf).
Skills: Collision detection, Arrays and objects
← Crash into the walls The game over message →