Workshop › OutRun-style Racer › Step 39 of 44
Show the best lap
What we are doing
Once there is a best lap, the text shows it too: Lap 2/3 3.1 Best 25.0. Before the first lap is done, nothing is
added.
```js
ctx.fillText('Lap ' + lap + '/' + LAPS + ' ' + seconds(lapTime) + (best ? ' Best ' + seconds(best) : ''), W - 10, 22)
```
What it means
(best ? ' Best ' + seconds(best) : '') adds the best time when there is one, otherwise an empty text. 0 counts as
false.
Your turn
At the end of the Lap text, before , W - 10, 22), add the best part.
Skills: Drawing on a canvas
← Best lap Racing or finished →
All steps
- Sky and ground
- Draw again and again
- Perspective
- One piece of road
- A road made of segments
- Where we are on the track
- The road ahead
- Stripes
- Paint from far to near
- Kerbs and a center line
- Striped grass
- Moving is one number
- Which keys are down?
- The gas pedal
- Brake, coast and a top speed
- Your car
- Speedometer
- A pedal for phones
- Move the camera sideways
- Steering
- No turning on the spot
- The grass is slow
- Steering by touch
- A track with curves
- Bend the road
- No jumps in the curve
- Which segment am I on?
- Curves pull you outwards
- Other cars
- Distance on a loop
- Cars that shrink with distance
- Traffic moves
- Rear-end crash
- Counting laps
- Show the lap
- A lap timer
- Show the time
- Best lap
- Show the best lap
- Racing or finished
- The finish line
- Finished!
- Race again
- Build it yourself: beat the clock