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.tsandindex.cssare read-only;world.tsis hidden but importable. - Start idle:
start-gamereads "Start", the globe has nodata-active-code,guess-formis not rendered,timerreads15s, andscorereadsSolved 0 of 0. - Clicking
start-gamestarts round 1: the form appears,start-gamehides, andworld-mapgets adata-active-code. - During a round the globe highlights exactly one
active-country, exposes the target asdata-active-code, its center asdata-center="lon,lat"(one decimal) and adata-zoomgreater than 1. -
timercounts down one second per tick from 15 using the${timeLeft}sformat, andscorereadsSolved {solved} of {played}. -
time-pieanimates while playing and pauses once the round is revealed. -
guess-formcontainsguess-input(withautoCompleteoff) andguess-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
AnswerOverlaywith the country name and disable the input. -
revealends 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_MSthe 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:
timerreadsDone, the form hides, the final score stays visible, andstart-gamereads "Play again" and starts a fresh game atSolved 0 of 0.
💡 Notes
- Use a self-rescheduling
setTimeoutinstead ofsetInterval, and returnclearTimeout— 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 guardround >= TOTAL_ROUNDSso no 11th round ever starts.
🧪 Tests
- renders the visible hemisphere with exactly one active country
- centers the globe on the highlighted country
- zooms the globe in to make the target easier to read
- only shows the locator for tiny target countries
- starts idle and begins a game from the Start button
- counts down one second per tick
- filters suggestions as the user types and caps them at six
- submits the clicked suggestion as a guess
- ends the round after a wrong guess and advances automatically
- ignores empty and whitespace-only guesses
- accepts the country name case-insensitively
- accepts the ISO country code
- shows the answer over the globe and advances when time runs out
- disables the input and ignores guesses after the reveal
- stops the countdown while the revealed answer is shown
- pauses the radial timer when the round is revealed
- starts a new round with a different country and a reset clock
- plays exactly 10 rounds and offers a replay
- 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.