Workshop › Battleship › Step 19 of 35
When the last enemy ship sinks you win, and the number of shots it took is your score: fewer is better.
```js
let state // 'playing', 'won' or 'lost'
let shots // how many shots you took
state = 'playing'
shots = 0
if (state !== 'playing' || myShots[r][c]) return
shots += 1
if (enemyFleet.every(sunk)) {
state = 'won'
message = 'You won in ' + shots + ' shots!'
return
}
```playerShoots does nothing unless playing, and counts every real shot.enemyFleet.every(sunk) is true when all enemy ships are sunk: you won, and the message shows the shots.let message write let state and let shots with their comments.reset, under the message line, write state = 'playing' and shots = 0.playerShoots, change the first line and write shots += 1 under it.playerShoots, write the win block.Skills: Game states
← Outline sunk ships A record of their shots →