Countdown timers in React are where setInterval goes to die. The interval keeps ticking after the round ends, the UI updates with stale values, and the cleanup you forgot turns into a memory leak. This challenge replaces that pattern with a self-rescheduling setTimeout that you own from start to finish.

🧩 Overview

Build a 10-round timed globe-guessing game: a country is highlighted in red on a 3D globe and you have 15 seconds to name it. It's a small game that drills three things you use in every app — effect cleanup, countdown timers, and resetting state between rounds.

👉 https://www.reactchallenges.com/challenges/country-guess

✅ Requirements

  • Implement the game in App.tsx. WorldMap.tsx, AnswerOverlay.tsx, SuggestionsList.tsx, TimerPie.tsx, utils.ts and index.css are read-only; world.ts is hidden but importable.
  • Start idle: start-game reads "Start", the globe has no data-active-code, guess-form is not rendered, timer reads 15s, and score reads Solved 0 of 0.
  • Clicking start-game starts round 1: the form appears, start-game hides, and world-map gets a data-active-code.
  • During a round the globe highlights exactly one active-country, exposes the target as data-active-code, its center as data-center="lon,lat" (one decimal) and a data-zoom greater than 1.
  • timer counts down one second per tick from 15 using the ${timeLeft}s format, and score reads Solved {solved} of {played}.
  • time-pie animates while playing and pauses once the round is revealed.
  • guess-form contains guess-input (with autoComplete off) and guess-submit; guesses are trimmed and compared case-insensitively against the country name or ISO code.
  • Empty or whitespace-only guesses are ignored and keep the round alive.
  • Typing filters up to six name matches through SuggestionsList; clicking a suggestion submits that country.
  • A correct guess adds one solved and one played round; a wrong guess adds only one played round. Both reveal AnswerOverlay with the country name and disable the input.
  • reveal ends the round without a point, disables the input and ignores later submissions.
  • The countdown stops as soon as the round is revealed, and reaching 0 ends the round without a point.
  • After AUTO_ADVANCE_MS the next round starts with a different country, a 15s clock, an empty input and no overlay; the score persists.
  • After 10 rounds the game ends: timer reads Done, the form hides, the final score stays visible, and start-game reads "Play again" and starts a fresh game at Solved 0 of 0.

💡 Notes

  • Use a self-rescheduling setTimeout instead of setInterval, and return clearTimeout — stop scheduling once the round is revealed.
  • Update the clock with a functional setter, setTimeLeft((current) => current - 1), so each tick builds on the latest value.
  • Auto-advance from an effect that watches outcome, and guard round >= TOTAL_ROUNDS so no 11th round ever starts.

🧪 Tests

  1. renders the visible hemisphere with exactly one active country
  2. centers the globe on the highlighted country
  3. zooms the globe in to make the target easier to read
  4. only shows the locator for tiny target countries
  5. starts idle and begins a game from the Start button
  6. counts down one second per tick
  7. filters suggestions as the user types and caps them at six
  8. submits the clicked suggestion as a guess
  9. ends the round after a wrong guess and advances automatically
  10. ignores empty and whitespace-only guesses
  11. accepts the country name case-insensitively
  12. accepts the ISO country code
  13. shows the answer over the globe and advances when time runs out
  14. disables the input and ignores guesses after the reveal
  15. stops the countdown while the revealed answer is shown
  16. pauses the radial timer when the round is revealed
  17. starts a new round with a different country and a reset clock
  18. plays exactly 10 rounds and offers a replay
  19. tracks solved and played across rounds

By the end you'll have a countdown you can trust: one timer, one cleanup path, and state that resets on every round instead of leaking into the next one.

🔥 Start the Challenge Now