Workshop › Whack-a-Mole › Step 16 of 18

Remember each hit

What we are doing

A hit should feel good: a "+1" will float up from the mole. First we keep a list of them: each hit adds one with its place and the time it was born, and each one is forgotten after 600 ms.

```js
let popups = [] // floating "+1"s: { x, y, born }

  popups = []

    popups.push({ x: hole.x, y: hole.y - 40, born: now })

  popups = popups.filter((p) => now - p.born < 600)
```

What it means

Your turn

  1. Under let best, write let popups.
  2. In start, empty the list; in the listener, add a popup on a hit.
  3. Make the filter line the first line of update.

Skills: Arrays and objects

All steps

  1. A green field
  2. Nine holes
  3. Draw the holes
  4. A clock and a loop
  5. A mole in a hole
  6. Moles pop up
  7. Which hole was clicked?
  8. Whack!
  9. Show the score
  10. Click to start
  11. Time's running
  12. Time's up
  13. Best score
  14. How far into the round?
  15. Faster and faster
  16. Remember each hit
  17. Floating +1
  18. Build it yourself: combos