Back

React Tic-Tac-Toe Engine

medium

Streak

0 days

Progress

0%

Submitted

0

React Tic-Tac-Toe Engine

React30 minmediumFree

Prompt

Build this React exercise in 30 minutes.

Build a local two-player 3×3 game. X moves first. Use one board array; derive the player, winner, draw, and status. No AI, network, or custom grid keyboard model is required; native buttons support Tab and Enter/Space.

Acceptance checks

  • Each of the eight winning lines is detected for X and O.
  • An occupied cell or a click after a win leaves the board unchanged.
  • Moves 1,2,3,5,4,6,8,7,9 produce a draw; Restart clears all cells and X moves first.
  • Every cell has a row/column/value accessible name; the status announces the result.

The checks are a manual interview checklist; saving a submission does not execute them.

Learn and continue

Prerequisite: Immutable state. Work through the React Machine Coding Foundations path to practice related skills in order.

Requirements

  • →Each of the eight winning lines is detected for X and O.
  • →An occupied cell or a click after a win leaves the board unchanged.
  • →Moves 1,2,3,5,4,6,8,7,9 produce a draw; Restart clears all cells and X moves first.
  • →Every cell has a row/column/value accessible name; the status announces the result.

Starter packet

What the interviewer handed you

Build a local two-player 3×3 game. X moves first. Use one board array; derive the player, winner, draw, and status. No AI, network, or custom grid keyboard model is required; native buttons support Tab and Enter/Space.

Manual acceptance checks

  • Each of the eight winning lines is detected for X and O.
  • An occupied cell or a click after a win leaves the board unchanged.
  • Moves 1,2,3,5,4,6,8,7,9 produce a draw; Restart clears all cells and X moves first.
  • Every cell has a row/column/value accessible name; the status announces the result.

Likely follow-ups

  • • How would you add move history without duplicating the current board?
Example
Loading preview...
For the best coding experience, we recommend using a desktop device.
Preparing Sandbox...
Premium interview report

What interviewers score in this build

Use this before reading the code. It tells you what to say, what to test, and where machine-coding candidates usually lose points.

Interview signals

  • State and behavior: Each of the eight winning lines is detected for X and O.
  • Edge cases: Every cell has a row/column/value accessible name; the status announces the result.
  • Explanation: Explain the state model and demonstrate the acceptance checks.

Time checkpoints

  1. 1

    0:00: Read the contract and inspect the fixtures.

  2. 2

    10:00: Complete the state and interaction handlers.

  3. 3

    20:00: Check keyboard use and boundary behavior.

  4. 4

    30:00: Run every acceptance check and explain tradeoffs.

Edge-case checklist

Each of the eight winning lines is detected for X and O.
An occupied cell or a click after a win leaves the board unchanged.
Moves 1,2,3,5,4,6,8,7,9 produce a draw; Restart clears all cells and X moves first.
Every cell has a row/column/value accessible name; the status announces the result.

Common mistakes

  • How would you add move history without duplicating the current board?
SolutionRead-only · Live Preview

Technical Explanation

One source of truth

The nine cells describe the game. Counting filled cells tells us whose turn comes next; checking eight lines finds a winner. A full board without a winner is a draw.

Apply moves to the latest board

setBoard(previous => play(previous, index)) prevents queued clicks from computing against the same old board. play rejects occupied cells and finished games, then returns a copy. Restart creates a fresh empty board.

Keyboard and status

Native buttons support ordinary keyboard activation. A polite status region communicates the next turn and result. This is a button group layout, not an ARIA grid; arrow-key navigation would need a separate contract.

Interview Criteria

State and behavior

Each of the eight winning lines is detected for X and O.

Edge cases

Every cell has a row/column/value accessible name; the status announces the result.

Explanation

Explain the state model and demonstrate the acceptance checks.

Time Checkpoints

0:00

0:00: Read the contract and inspect the fixtures.

10:00

10:00: Complete the state and interaction handlers.

20:00

20:00: Check keyboard use and boundary behavior.

30:00

30:00: Run every acceptance check and explain tradeoffs.

Streak

0 days

Last active: Sign in to track

Progress

0%

0/0 solved

Submitted

0

Solutions pushed to review history.

More Machine Coding

View all Machine Coding →
Machine CodingMedium

Performant Image Slider

Machine CodingMedium

API Search and Render Image

Machine CodingEasy

Accessible React Tabs

Machine CodingMedium

Recursive File Explorer

Machine CodingEasy

Stopwatch

Machine CodingEasy

Tooltip

Related hubs

  • All machine coding
  • Frontend machine coding guide
  • React machine coding questions
  • UI coding interview questions
  • React UI interview questions
  • Google interview
  • Microsoft interview
  • Uber interview

FAQ

Why is Tic-Tac-Toe a common React machine coding prompt?

It is small enough to finish in one round but still forces board state, turn management, win detection, and immutable updates — all core React interview signals.

What edge cases should I handle?

Prevent moves on filled cells or after a winner, support reset, and keep the win/draw logic pure so it is easy to test and explain.

What related UI rounds should I practice next?

Tabs, accordion, modal system, and multi-step form — they reuse state modeling and interaction patterns from this challenge.