Become a member
to unlock all features

Create egghead account to access 5000+ tutorials and resources from expert developers.

Create account

    Checking for Winning Conditions in Tic-Tac-Toe


    At this point, our game is fully usable. Users can add Xs and Os and can see for themselves who has won or not. However, this is a computer game now and it should be programmed to determine who the winner is algorithmically.

    Breaking down the problem of tic-tac-toe, one will realize that there are only 8 winning conditions in the game. We can create a handful of functions that will checkForWin when a square is clicked. Once we have determined the winner, we can update the UI to announce that to the users.