Memory GameLoading saved progress…

Memory Game

Build a memory (concentration) game: a grid of face-down cards; flip two and if they match they stay, otherwise they flip back. Match all pairs to win. The state is small — which cards are face-up right now, and which are permanently matched — and the only timing piece is the brief pause before a non-matching pair flips back.

Signature

// A self-contained component. No props.
function App(): JSX.Element;

A grid of cards; flip pairs to match them.

Examples

flip card 0 (🍎), flip card 7 (🍎) → match → both stay face-up
flip card 1 (🍌), flip card 2 (🍇) → no match → both flip back after a moment
clicking is ignored while two cards are already face-up, or on a matched card
all pairs matched → "You win!"

Notes

  • Two pieces of state. flipped (the up-to-2 face-up indices) and matched (a set of solved indices).
  • Compare on the second flip. Same value → add both to matched; different → clear flipped after a delay.
  • Card face. A card shows its emoji when it's flipped or matched, otherwise a back.
  • Guard clicks. Ignore clicks when two are already up, or on already-flipped/matched cards.
Loading editor…
Loading preview…