Workshop › Whack-a-Mole › Step 6 of 18
Every 700 ms a mole pops up in a random empty hole and stays up for one second.
```js
let nextPop = 0 // when the next mole pops up
function update() {
if (now >= nextPop) {
const empty = holes.filter((hole) => !isUp(hole))
if (empty.length > 0) {
const hole = empty[Math.floor(Math.random() * empty.length)]
hole.upUntil = now + 1000
}
nextPop = now + 700
}
}
update()
```now >= nextPop), pick among the holes without a mole.let now, write let nextPop = 0.function draw() {, write update.loop, call update() before draw().Skills: Game states, The game loop
← A mole in a hole Which hole was clicked? →