Workshop › 2048 › Step 20 of 26
Making a 2048 tile is a win, but the game can go on to 4096 and beyond. So winning is its own state, 'won', and a
keepPlaying flag remembers when the player chose to continue, so the win does not come back every move.
```js
let keepPlaying // true once the player chose to continue after making 2048
keepPlaying = false
if (!keepPlaying && board.some((row) => row.includes(2048))) state = 'won'
else if (!canMove()) state = 'over'
```row.includes(2048) is true if the row has a 2048; board.some(...) is true if any row does.'won'; otherwise, as before, a stuck
board is 'over'.let state write let keepPlaying; in newGame, under state = 'playing', write keepPlaying = false.move, replace the canMove line with the two lines.Skills: Game states, Arrays and objects
← Game over Win and lose screens →