Tic Tac Toe Lab Exercise Part 4-5

Step 4

The state of the game should be rendered to the user.

a. Create a function called render, then set it aside for now.

b. Create a function called updateBoard.

c. In the updateBoard function, loop over board and for each element:

d. Create a function called updateMessage.

e. In updateMessage, render a message based on the current game state:

f. Invoke both the updateBoard and the updateMessage functions inside your render function.

After completing all of step 4, you should be able to manually change the values held in the board array in the init() function and see the style of the corresponding square change on your page.

For example, when the board array is a collection of empty strings, you should see something like this: Empty board

If the board holds an X and O in the top left and top middle positions, you should see something like this: Active board

Step 5

Define the required constants.

a. In a constant called winningCombos, define the eight possible winning combinations as an array of arrays.

🧠 Each array will contain three indices of the board that make a winner if they hold the same player value ('X' or 'O').