Workshop › 2048 › Step 17 of 26
Every merge scores the value of the new tile: slideRow already returns it as gained. We add it up in score and
show it in the strip above the board.
```js
let score
score = 0
const { row, gained } = slideRow(line)
if (reversed) row.reverse()
score += gained
ctx.fillStyle = '#776e65'
ctx.font = 'bold 22px sans-serif'
ctx.textAlign = 'left'
ctx.textBaseline = 'middle'
ctx.fillText('Score: ' + score, GAP, TOP / 2)
```score is 0 in a new game.const { row, gained } now takes both properties out of slideRow's result, and gained is added to score.textBaseline = 'middle' already applies.let board write let score; in newGame, under board = ..., write score = 0.move, take gained too and add it to score after the row.reverse() line.draw, write the three pen lines above textBaseline, and the fillText line under it.Skills: Game states
← Up and down are columns Is there a move left? →