Workshop › 2048 › Step 19 of 26
A state variable says whether the game is 'playing' or 'over'. After a move, if no move is left, it is over, and
move does nothing any more.
```js
let state // 'playing', 'won' or 'over'
state = 'playing'
function move(direction) {
if (state !== 'playing') return false
addTile()
if (!canMove()) state = 'over'
return true
}
```'playing'. move stops at once unless the game is playing.!canMove() means stuck: the state becomes 'over'.let score write let state; in newGame, under score = 0, write state = 'playing'.move.move, under addTile(), write the canMove line.Skills: Game states
← Is there a move left? Making 2048 →