Workshop › Whack-a-Mole › Step 4 of 18
Moles come and go with time, so the game needs a clock. A loop redraws about 60 times a second, and the browser tells
it the time in milliseconds; we keep it in now.
```js
let now = 0 // time of the current frame, in ms
function loop(time) {
now = time
draw()
requestAnimationFrame(loop)
}
requestAnimationFrame(loop)
```requestAnimationFrame(loop) asks the browser to run loop before the next screen refresh, passing the time.loop saves the time, draws, and asks again, so it never stops.draw()).let now = 0.draw() call at the bottom with loop and requestAnimationFrame(loop).Skills: The game loop
← Draw the holes A mole in a hole →