File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -84,6 +84,11 @@ function gameOver(gameWon) {
8484 }
8585}
8686
87+ function declareWinner ( whoWin ) {
88+ document . querySelector ( ".endgame" ) . style . display = "block" ;
89+ document . querySelector ( ".endgame .text" ) . innerText = whoWin ;
90+ }
91+
8792function emptySquares ( ) {
8893 //filter every element from the board array
8994 return origBoard . filter ( s => typeof s == 'number' ) ;
@@ -92,3 +97,15 @@ function emptySquares() {
9297function bestSpot ( ) { //Find all blank cells and get first element from blank cell. So the AI will always play the first slot
9398 return emptySquares ( ) [ 0 ] ;
9499}
100+
101+ function checkTie ( ) {
102+ if ( emptySquares ( ) . length == 0 ) {
103+ for ( var i = 0 ; i < cells . length ; i ++ ) {
104+ cells [ i ] . style . backgroundColor = "pink" ;
105+ cells [ i ] . removeEventListener ( 'click' , turnClick , false ) ;
106+ }
107+ declareWinner ( "Tie Game!" )
108+ return true ;
109+ }
110+ return false ;
111+ }
You can’t perform that action at this time.
0 commit comments