DEV Community

Discussion on: Pure and Simple - Tic Tac Toe with Javascript

Collapse
 
cnorman19 profile image
Cameron Norman

Hello Sir, modifying this solution to make it work for a 4x4 tic tac toe game but I am having some trouble getting it to work and I'm not quite understanding why. Any help would be highly appreciated. I will list the steps I have taken in order to accomplish that and maybe you can tell me where I went wrong.

  1. Adding more cells to our board by modifying both the HTML and CSS.
  2. Modifying the win conditions in order to accommodate for the change in board size
for (let i = 0; i <= 15; i++) {
        const winCondition = winningConditions[i];
        let a = gameState[winCondition[0]];
        let b = gameState[winCondition[1]];
        let c = gameState[winCondition[2]];
        let d = gameState[winCondition[3]];

        if (a === '' || b === '' || c === '' || d === '') {
            continue;
        }
        if (a === b && b === c && c === d) {
            roundWon = true;
            break; 
        }
    }
Enter fullscreen mode Exit fullscreen mode
  1. Lastly I modified the gamestate to reflect the additional cells.

Like I said any help would be greatly appreciated! If you would like to look at the full code let me know! Thank you for your time!

Collapse
 
cnorman19 profile image
Cameron Norman

Sorry, realized immediately after posting this that my for-loop should look like this. Got a little confused on what exactly was taking place.

for (let i = 0; i <= 9; i++)

Everything works perfect now. Thank you.

Collapse
 
bornasepic profile image
Borna Šepić

Ah the rubber duck debugging at it's finest :)

Glad you sorted it out!