Workshop › Sudoku › Step 15 of 28
Sudoku players race the clock. The loop counts frames until the puzzle is solved, and the time is shown as minutes and seconds.
```js
let frames
frames = 0
if (!won) frames += 1
const seconds = Math.floor(frames / 60)
const clock = (s) => Math.floor(s / 60) + ':' + String(s % 60).padStart(2, '0')
ctx.fillStyle = '#0f172a'
ctx.font = 'bold 18px sans-serif'
ctx.textAlign = 'left'
ctx.fillText('Time ' + clock(seconds), LEFT, 34)
```frames counts loop turns while the puzzle is not solved; 60 frames are one second.clock turns seconds into m:ss: 75 becomes 1:15, and padStart(2, '0') makes 5 seconds 05.let selected, write let frames; in reset, set it to 0.loop, count frames while not won.draw, write the time lines.Skills: The game loop
← Solved! The solved message →