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

Whack!

What we are doing

A click on a hole whose mole is up scores a point and sends the mole back down at once.

```js
let score = 0

canvas.addEventListener('pointerdown', (event) => {
  // The canvas may be displayed at a different size than its own pixels, so scale the pointer.
  const rect = canvas.getBoundingClientRect()
  const x = (event.clientX - rect.left) * (canvas.width / rect.width)
  const y = (event.clientY - rect.top) * (canvas.height / rect.height)
  const hole = holeAt(x, y)
  if (hole && isUp(hole)) {
    score += 1
    hole.upUntil = 0
  }
})
```

What it means

Your turn

  1. Under let nextPop, write let score = 0.
  2. Above update, write the pointerdown listener.

Skills: Keyboard and mouse input

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