Play Noughts and Crosses
Write the code, see it run, pass the checks.
The problem
- hard
- Code
- Pro
Build noughts and crosses for two players sharing a screen. The nine squares are buttons with aria-label "Square 1" to "Square 9", row by row from the top left, each showing "X", "O" or nothing. A line reads "Next: X" or "Next: O", and X goes first. Clicking an empty square marks it for the player whose turn it is; clicking a marked square does nothing. When a player has three in a row, column or diagonal, the line reads "Winner: X" (or O) and every square is disabled. When all nine are filled and nobody has a line, it reads "Draw". A "Restart" button empties the board, and X goes first again.
Your code must pass
- X goes first and turns alternate
- Clicking a marked square does nothing
- Three in a row wins and stops the game
- A full board with no line is a draw
- Winning on the last square is a win, not a draw
- Restart starts a new game