Workshop › 15 Puzzle › Step 24 of 27
Show the win
What we are doing
Once solved, the tiles turn green and the top right says Solved! Click to shuffle.
```js
function drawTile(number, x, y) {
ctx.fillStyle = state === 'solved' ? '#16a34a' : '#f59e0b'
ctx.fillText('Moves ' + moves, LEFT, 36)
ctx.textAlign = 'right'
ctx.fillText(state === 'solved' ? 'Solved! Click to shuffle' : '', canvas.width - LEFT, 36)
```
What it means
condition ? a : b picks green when solved, orange otherwise.
- The message is right-aligned to the board's right edge; while playing it is empty text.
Your turn
- In
drawTile, change the first line to the ? : color.
- In
draw, under the Moves line, write the two lines. Press Run.
Skills: Drawing on a canvas, Game states
← Solved! Play again →
All steps
- A board in one list
- The canvas and the pen
- Paint the table
- A function that draws
- Row and column
- Where each square is
- Draw one tile
- The number on the tile
- All the tiles
- Draw again and again
- The solved board from N
- Neighbours
- Slide a tile
- Click a tile
- Arrow keys
- Count the moves
- Shuffle with real slides
- Which boards can be solved?
- Is it solved?
- Remember the slide
- Count the frames
- Smooth sliding
- Solved!
- Show the win
- Play again
- A record to beat
- Build it yourself: a timer