All Challenges

Tic-Tac-Toe with Win Detection & Move History

ReactMediumMetaAtlassianFlipkart
45:00

Problem Brief

Build an N=3 Tic-Tac-Toe game with alternating X/O turns, winner detection, draw detection, and time-travel move history buttons.

Requirements

  • Render 9 square buttons `[data-cell="0..8"]` inside `[data-testid="board"]`.
  • Clicking an empty cell fills `X` or `O` and appends a history step button inside `[data-testid="history"]`.
  • Freeze moves once a winner or draw is reached and show result in `[data-testid="status"]`.
  • Clicking `[data-step="N"]` rewinds board state back to move N.
Progressive Hints (1)
  • Store `history = [Array(9).fill(null)]` and `stepIndex`; slice history on rewind before playing a new branch.
Reference Solution

Stuck? Load the verified reference code into your editor.

Automated Test Suite

2 Test Cases Ready
  • Detects X winner and locks remaining empty squaresTop row X X X declares Winner: X
  • Rewinds board cleanly via move history buttonClicking Move #2 restores earlier state
solution.html
Live Sandboxed Previewiframe sandbox
Starter template loaded — add your <script> logic in the editor (or open Reference Solution) to make the widget interactive.