DEV Community

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

Collapse
 
jeffmx profile image
jeff-mx

Great code, I'am just starting with JS so I find it very usefull. I add the next lines in order to set a color to every player.

function handleCellPlayed(clickedCell, clickedCellIndex) {
/*
We update our internal game state to reflect the played move,
as well as update the user interface to reflect the played move
*/
gameState[clickedCellIndex] = currentPlayer;
clickedCell.innerHTML = currentPlayer;

    if ( currentPlayer == "X" ) { 
        document.querySelectorAll('.cell')[clickedCellIndex].style.color = "blue";
    }else{
        document.querySelectorAll('.cell')[clickedCellIndex].style.color = "red";
    }
}
Enter fullscreen mode Exit fullscreen mode
Collapse
 
bornasepic profile image
Borna Šepić

Hey Jeff, that's a great idea!
Always happy to see someone taking the tutorial a step further :)

Collapse
 
pcamellon profile image
Pcamellon

I think it might be better use ===.