Workshop › Candy Crush-style Match 3 › Step 12 of 29
Matches will score points. reset() sets up everything a game starts with (a new board, nothing selected, a score
of 0) and runs once when the page loads. The score is written at the top left.
```js
let score
function reset() {
newBoard()
selected = null
score = 0
}
ctx.fillStyle = 'white'
ctx.font = 'bold 18px sans-serif'
ctx.textAlign = 'left'
ctx.fillText('Score ' + score, LEFT, 30)
reset()
requestAnimationFrame(loop)
```reset makes a new board and sets selected and score to their starting values. It replaces the newBoard()
call at the bottom.font sets the text size and style, textAlign = 'left' starts the text at the given x, and fillText writes it.
'Score ' + score joins the word and the number.let selected write let score.// Every cell that is part... comment write reset.newBoard() with reset().draw, at the end, leave an empty line and write the four text lines.Skills: Game states, Functions
← No match, no swap Clear the match →