Build a whack-a-mole game. A 3 × 3 field of holes is shown. While the game runs, moles pop up in random holes, and the player scores a point for each mole they hit before it disappears.
The starter renders the static field, a score and a Start game button, and exports a WhackAMole component.
export function WhackAMole({
holes = 9,
duration = 15000, // length of one game in ms
moleInterval = 900, // how often a new set of moles appears
random = Math.random, // injectable for deterministic tests
})
moleInterval ms.duration ms the round ends: all moles disappear, the holes stop responding, and Time's up! Final score: N appears. The button then reads Play again.Hole 3, mole or Hole 3, empty.role="status").prefers-reduced-motion for the pop-up animation.setInterval(…, 1000) drift, and how do you make it accurate?Spotted a mistake or a rights concern? Report an issue