Tic-Tac-Toe Project

Create a two-player Tic-Tac-Toe game. Players take turns marking 'X' and 'O' on the grid, aiming to get three in a row—horizontally, vertically, or diagonally. Design the layout and handle win, lose, and tie conditions.

  • Resources: Background Image, Icons.

  • Things you need to know: Conditionals, Functions, HTML DOM Selection and Manipulation, Browser Events.

Max Chat

Task 1

  1. Add a background image to the body of the page using the provided resource.

  2. Add a heading with the text, Tic-Tac-Toe.

Tic-Tac-Toe Project - Task 1

Task 2

  1. Create a basic 3 x 3 grid structure.

  2. Ensure that the grid doesn't change shape on different screen sizes.

  3. Add a Reset button.

  4. Style the button as shown in the adjacent image.

Tic-Tac-Toe Project - Task 2

Task 3

  1. Add functionality to show player moves.

  2. The game should keep a count of clicks on the 3 x 3 grid.

  3. Any time an empty cell is clicked in the game, it should add either an X or an O inside that cell. Get these icons from the provided resource.

  4. When an empty cell is clicked, if the number of clicks inside the grid is odd, add an X inside the cell.

  5. When an empty cell is clicked, if the number of clicks inside the grid is even, add an O inside the cell.

  6. Ensure that you only count the first click on a cell. Once the cell shows either an X or an O, any further clicks on that cell should be meaningless.

  7. Add functionality in the Reset button so that when clicked, it should remove all Xs and Os from the grid. This should restore the game to its initial state so that a new game can be started.

Tic-Tac-Toe Project - Task 3

Task 4

  1. The icons could be in the same vertical, horizontal or diagonal line.

  2. Display the winner by adding text below the grid and above the Reset button.

  3. The text should say O wins! if there are three Os in a straight line.

  4. The text should say X wins! if there are three Xs in a straight line.

  5. Change the background colour to lightgreen for the three cells which make the winning line.

Tic-Tac-Toe Project - Task 4