Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="container">
  <div class="row" id="row1">
    <div class="square right" id="0"></div>
    <div class="square" id="1"></div>
    <div class="square" id="2"></div>
  </div>
  <div class="row" id="row2">
    <div class="square right" id="3"></div>
    <div class="square" id="4"></div>
    <div class="square" id="5"></div>
  </div>
  <div class="row" id="row3">
    <div class="square right" id="6"></div>
    <div class="square" id="7"></div>
    <div class="square" id="8"></div>
  </div>

  <button class="btn" id="choose-x">X</button>
  <button class="btn" id="choose-o">O</button>
  <button class="btn" id="new-game">New Game</button>
  <div class="result" id="result"></div>
</div>
              
            
!

CSS

              
                * {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: sans-serif;
}

body {
  display: flex;
}

.container {
  max-width: 60%;
  margin: 10px auto;
  align-items: center;
  vertical-align: top;
}

.row {
  vertical-align: top;
}

.square {
  display: inline-block;
  height: 100px;
  width: 100px;
  background: rgba(0, 39, 216, 0.8);
  text-align: center;
  border-radius: 10px;
  vertical-align: top;
  margin-bottom: 5px;
  line-height: 100px;
  color: white;
}

.square p {
  font-size: 60px;
}

.btn {
  width: 49%;
  height: 60px;
  display: inline-block;
  background: none;
  border: 3px solid rgba(0, 39, 216, 0.8);
  font-size: 36px;
}

button:hover {
  background-color: rgba(0, 39, 216, 0.8);
  color: white;
}

.disabled {
  pointer-events: none;
}

#new-game {
  width: 100%;
  margin-top: 5px;
  display: none;
}

.result p {
  font-size: 26px;
  text-align: center;
}

@media screen and (max-width: 535px) {
  .container {
    max-width: 235px;
  }
  
  .square {
    height: 75px;
    width: 75px;
    line-height: 75px;
  }
  
  #new-game {
    max-width: 100%;
  }
}
              
            
!

JS

              
                  var player = "x";
  var computer = "o";
  var turnCount = 0;
  var squareNumber = document.getElementsByClassName("square");
  var result = document.getElementById("result");
  var newGame = document.getElementById("new-game");

  $("#choose-x").click(function() {
    player = "x";
    computer = "o";
  })

  $("#choose-o").click(function() {
    player = "o";
    computer = "x";
  })

  $(".square").click(runWhenClicked);

  $("#new-game").click(resetGame);

  function runWhenClicked() {
    turnCount++;
    console.log("turncount = " + turnCount);
    console.log(this.id);
    this.innerHTML = "<p>" + player + "</p>";
    $("#" + this.id).addClass("disabled");
    checkForWin();
    computerMove();
    checkForWin();
  };

  function computerMove() {
    turnCount++;
    console.log("turncount = " + turnCount);

    // Priority #1: Win the game.             
    // Priority #2: Prevent human from winning the game.
    // Priority #3: Prevent human from making forks.
    // Priority #4: Choose an open space.

    // Priority 1: Win the game BEGIN

    // test cases for winning computer combination [0, 1, 2]
    if ($("#0").text().indexOf("") === 0 && $("#0").text().indexOf(player) !== 0 && $("#1").text().indexOf(computer) >= 0 && $("#2").text().indexOf(computer) >= 0) {
      $("#0").append("<p>" + computer + "</p>");
      $("#0").addClass("disabled");
    } else if ($("#0").text().indexOf(computer) >= 0 && $("#1").text().indexOf("") === 0 && $("#1").text().indexOf(player) !== 0 && $("#2").text().indexOf(computer) >= 0) {
      $("#1").append("<p>" + computer + "</p>");
      $("#1").addClass("disabled");
    } else if ($("#0").text().indexOf(computer) >= 0 && $("#1").text().indexOf(computer) >= 0 && $("#2").text().indexOf("") === 0 && $("#2").text().indexOf(player) !== 0) {
      $("#2").append("<p>" + computer + "</p>");
      $("#2").addClass("disabled");
      // test cases for winning computer combination [3, 4, 5]    
    } else if ($("#3").text().indexOf("") === 0 && $("#3").text().indexOf(player) !== 0 && $("#4").text().indexOf(computer) >= 0 && $("#5").text().indexOf(computer) >= 0) {
      $("#3").append("<p>" + computer + "</p>");
      $("#3").addClass("disabled");
    } else if ($("#3").text().indexOf(computer) >= 0 && $("#4").text().indexOf("") === 0 && $("#4").text().indexOf(player) !== 0 && $("#5").text().indexOf(computer) >= 0) {
      $("#4").append("<p>" + computer + "</p>");
      $("#4").addClass("disabled");
    } else if ($("#3").text().indexOf(computer) >= 0 && $("#4").text().indexOf(computer) >= 0 && $("#5").text().indexOf("") === 0 && $("#5").text().indexOf(player) !== 0) {
      $("#5").append("<p>" + computer + "</p>");
      $("#5").addClass("disabled");
      // test cases for winning computer combination [6, 7, 8] //    
    } else if ($("#6").text().indexOf("") === 0 && $("#6").text().indexOf(player) !== 0 && $("#7").text().indexOf(computer) >= 0 && $("#8").text().indexOf(computer) >= 0) {
      $("#6").append("<p>" + computer + "</p>");
      $("#6").addClass("disabled");
    } else if ($("#6").text().indexOf(computer) >= 0 && $("#7").text().indexOf("") === 0 && $("#7").text().indexOf(player) !== 0 && $("#8").text().indexOf(computer) >= 0) {
      $("#7").append("<p>" + computer + "</p>");
      $("#7").addClass("disabled");
    } else if ($("#6").text().indexOf(computer) >= 0 && $("#7").text().indexOf(computer) >= 0 && $("#8").text().indexOf("") === 0 && $("#8").text().indexOf(player) !== 0) {
      $("#8").append("<p>" + computer + "</p>");
      $("#8").addClass("disabled");
      // test cases for winning computer combination [0, 3, 6] //    
    } else if ($("#0").text().indexOf("") === 0 && $("#0").text().indexOf(player) !== 0 && $("#3").text().indexOf(computer) >= 0 && $("#6").text().indexOf(computer) >= 0) {
      $("#0").append("<p>" + computer + "</p>");
      $("#0").addClass("disabled");
    } else if ($("#0").text().indexOf(computer) >= 0 && $("#3").text().indexOf("") === 0 && $("#3").text().indexOf(player) !== 0 && $("#6").text().indexOf(computer) >= 0) {
      $("#3").append("<p>" + computer + "</p>");
      $("#3").addClass("disabled");
    } else if ($("#0").text().indexOf(computer) >= 0 && $("#3").text().indexOf(computer) >= 0 && $("#6").text().indexOf("") === 0 && $("#6").text().indexOf(player) !== 0) {
      $("#6").append("<p>" + computer + "</p>");
      $("#6").addClass("disabled");
      // test cases for winning computer combination [1, 4, 7] //    
    } else if ($("#1").text().indexOf("") === 0 && $("#1").text().indexOf(player) !== 0 && $("#4").text().indexOf(computer) >= 0 && $("#7").text().indexOf(computer) >= 0) {
      $("#1").append("<p>" + computer + "</p>");
      $("#1").addClass("disabled");
    } else if ($("#1").text().indexOf(computer) >= 0 && $("#4").text().indexOf("") === 0 && $("#4").text().indexOf(player) !== 0 && $("#7").text().indexOf(computer) >= 0) {
      $("#4").append("<p>" + computer + "</p>");
      $("#4").addClass("disabled");
    } else if ($("#1").text().indexOf(computer) >= 0 && $("#4").text().indexOf(computer) >= 0 && $("#7").text().indexOf("") === 0 && $("#7").text().indexOf(player) !== 0) {
      $("#7").append("<p>" + computer + "</p>");
      $("#7").addClass("disabled");
      // test cases for winning computer combination [2, 5, 8] //    
    } else if ($("#2").text().indexOf("") === 0 && $("#2").text().indexOf(player) !== 0 && $("#5").text().indexOf(computer) >= 0 && $("#8").text().indexOf(computer) >= 0) {
      $("#2").append("<p>" + computer + "</p>");
      $("#2").addClass("disabled");
    } else if ($("#2").text().indexOf(computer) >= 0 && $("#5").text().indexOf("") === 0 && $("#5").text().indexOf(player) !== 0 && $("#8").text().indexOf(computer) >= 0) {
      $("#5").append("<p>" + computer + "</p>");
      $("#5").addClass("disabled");
    } else if ($("#2").text().indexOf(computer) >= 0 && $("#5").text().indexOf(computer) >= 0 && $("#8").text().indexOf("") === 0 && $("#8").text().indexOf(player) !== 0) {
      $("#8").append("<p>" + computer + "</p>");
      $("#8").addClass("disabled");
      // test cases for winning computer combination [2, 4, 6] //
    } else if ($("#2").text().indexOf("") === 0 && $("#2").text().indexOf(player) !== 0 && $("#4").text().indexOf(computer) >= 0 && $("#6").text().indexOf(computer) >= 0) {
      $("#2").append("<p>" + computer + "</p>");
      $("#2").addClass("disabled");
    } else if ($("#2").text().indexOf(computer) >= 0 && $("#4").text().indexOf("") === 0 && $("#4").text().indexOf(player) !== 0 && $("#6").text().indexOf(computer) >= 0) {
      $("#4").append("<p>" + computer + "</p>");
      $("#4").addClass("disabled");
    } else if ($("#2").text().indexOf(computer) >= 0 && $("#4").text().indexOf(computer) >= 0 && $("#6").text().indexOf("") === 0 && $("#6").text().indexOf(player) !== 0) {
      $("#6").append("<p>" + computer + "</p>");
      $("#6").addClass("disabled");
      // test cases for winning computer combination [0, 4, 8] //    
    } else if ($("#0").text().indexOf("") === 0 && $("#0").text().indexOf(player) !== 0 && $("#4").text().indexOf(computer) >= 0 && $("#8").text().indexOf(computer) >= 0) {
      $("#0").append("<p>" + computer + "</p>");
      $("#0").addClass("disabled");
    } else if ($("#0").text().indexOf(computer) >= 0 && $("#4").text().indexOf("") === 0 && $("#4").text().indexOf(player) !== 0 && $("#8").text().indexOf(computer) >= 0) {
      $("#4").append("<p>" + computer + "</p>");
      $("#4").addClass("disabled");
    } else if ($("#0").text().indexOf(computer) >= 0 && $("#4").text().indexOf(computer) >= 0 && $("#8").text().indexOf("") === 0 && $("#8").text().indexOf(player) !== 0) {
      $("#8").append("<p>" + computer + "</p>");
      $("#8").addClass("disabled");
    }

    // Priority 1: Win the game END

    // Priority 2: Prevent human from winning the game BEGIN

    // test cases for winning player winning combination [0, 1, 2] //    
    else if ($("#0").text().indexOf("") === 0 && $("#0").text().indexOf(computer) !== 0 && $("#1").text().indexOf(player) >= 0 && $("#2").text().indexOf(player) >= 0) {
      $("#0").append("<p>" + computer + "</p>");
      $("#0").addClass("disabled");
    } else if ($("#0").text().indexOf(player) >= 0 && $("#1").text().indexOf("") === 0 && $("#1").text().indexOf(computer) !== 0 && $("#2").text().indexOf(player) >= 0) {
      $("#1").append("<p>" + computer + "</p>");
      $("#1").addClass("disabled");
    } else if ($("#0").text().indexOf(player) >= 0 && $("#1").text().indexOf(player) >= 0 && $("#2").text().indexOf("") === 0 && $("#2").text().indexOf(computer) !== 0) {
      $("#2").append("<p>" + computer + "</p>");
      $("#2").addClass("disabled");
      // test cases for winning combination [3, 4, 5] //
    } else if ($("#3").text().indexOf("") === 0 && $("#3").text().indexOf(computer) !== 0 && $("#4").text().indexOf(player) >= 0 && $("#5").text().indexOf(player) >= 0) {
      $("#3").append("<p>" + computer + "</p>");
      $("#3").addClass("disabled");
    } else if ($("#3").text().indexOf(player) >= 0 && $("#4").text().indexOf("") === 0 && $("#4").text().indexOf(computer) !== 0 && $("#5").text().indexOf(player) >= 0) {
      console.log($("#4").text());
      $("#4").append("<p>" + computer + "</p>");
      $("#4").addClass("disabled");
    } else if ($("#3").text().indexOf(player) >= 0 && $("#4").text().indexOf(player) >= 0 && $("#5").text().indexOf("") === 0 && $("#5").text().indexOf(computer) !== 0) {
      $("#5").append("<p>" + computer + "</p>");
      $("#5").addClass("disabled");
      // test cases for winning combination [6, 7, 8] //    
    } else if ($("#6").text().indexOf("") === 0 && $("#6").text().indexOf(computer) !== 0 && $("#7").text().indexOf(player) >= 0 && $("#8").text().indexOf(player) >= 0) {
      $("#6").append("<p>" + computer + "</p>");
      $("#6").addClass("disabled");
    } else if ($("#6").text().indexOf(player) >= 0 && $("#7").text().indexOf("") === 0 && $("#7").text().indexOf(computer) !== 0 && $("#8").text().indexOf(player) >= 0) {
      $("#7").append("<p>" + computer + "</p>");
      $("#7").addClass("disabled");
    } else if ($("#6").text().indexOf(player) >= 0 && $("#7").text().indexOf(player) >= 0 && $("#8").text().indexOf("") === 0 && $("#8").text().indexOf(computer) !== 0) {
      $("#8").append("<p>" + computer + "</p>");
      $("#8").addClass("disabled");
      // test cases for winning combination [0, 3, 6] //    
    } else if ($("#0").text().indexOf("") === 0 && $("#0").text().indexOf(computer) !== 0 && $("#3").text().indexOf(player) >= 0 && $("#6").text().indexOf(player) >= 0) {
      $("#0").append("<p>" + computer + "</p>");
      $("#0").addClass("disabled");
    } else if ($("#0").text().indexOf(player) >= 0 && $("#3").text().indexOf("") === 0 && $("#3").text().indexOf(computer) !== 0 && $("#6").text().indexOf(player) >= 0) {
      $("#3").append("<p>" + computer + "</p>");
      $("#3").addClass("disabled");
    } else if ($("#0").text().indexOf(player) >= 0 && $("#3").text().indexOf(player) >= 0 && $("#6").text().indexOf("") === 0 && $("#6").text().indexOf(computer) !== 0) {
      $("#6").append("<p>" + computer + "</p>");
      $("#6").addClass("disabled");
      // test cases for winning combination [1, 4, 7] //    
    } else if ($("#1").text().indexOf("") === 0 && $("#1").text().indexOf(computer) !== 0 && $("#4").text().indexOf(player) >= 0 && $("#7").text().indexOf(player) >= 0) {
      $("#1").append("<p>" + computer + "</p>");
      $("#1").addClass("disabled");
    } else if ($("#1").text().indexOf(player) >= 0 && $("#4").text().indexOf("") === 0 && $("#4").text().indexOf(computer) !== 0 && $("#7").text().indexOf(player) >= 0) {
      $("#4").append("<p>" + computer + "</p>");
      $("#4").addClass("disabled");
    } else if ($("#1").text().indexOf(player) >= 0 && $("#4").text().indexOf(player) >= 0 && $("#7").text().indexOf("") === 0 && $("#7").text().indexOf(computer) !== 0) {
      $("#7").append("<p>" + computer + "</p>");
      $("#7").addClass("disabled");
      // test cases for winning combination [2, 5, 8] //    
    } else if ($("#2").text().indexOf("") === 0 && $("#2").text().indexOf(computer) !== 0 && $("#5").text().indexOf(player) >= 0 && $("#8").text().indexOf(player) >= 0) {
      $("#2").append("<p>" + computer + "</p>");
      $("#2").addClass("disabled");
    } else if ($("#2").text().indexOf(player) >= 0 && $("#5").text().indexOf("") === 0 && $("#5").text().indexOf(computer) !== 0 && $("#8").text().indexOf(player) >= 0) {
      $("#5").append("<p>" + computer + "</p>");
      $("#5").addClass("disabled");
    } else if ($("#2").text().indexOf(player) >= 0 && $("#5").text().indexOf(player) >= 0 && $("#8").text().indexOf("") === 0 && $("#8").text().indexOf(computer) !== 0) {
      $("#8").append("<p>" + computer + "</p>");
      $("#8").addClass("disabled");
      // test cases for winning combination [2, 4, 6] //    
    } else if ($("#2").text().indexOf("") === 0 && $("#2").text().indexOf(computer) !== 0 && $("#4").text().indexOf(player) >= 0 && $("#6").text().indexOf(player) >= 0) {
      $("#2").append("<p>" + computer + "</p>");
      $("#2").addClass("disabled");
    } else if ($("#2").text().indexOf(player) >= 0 && $("#4").text().indexOf("") === 0 && $("#4").text().indexOf(computer) !== 0 && $("#6").text().indexOf(player) >= 0) {
      $("#4").append("<p>" + computer + "</p>");
      $("#4").addClass("disabled");
    } else if ($("#2").text().indexOf(player) >= 0 && $("#4").text().indexOf(player) >= 0 && $("#6").text().indexOf("") === 0 && $("#6").text().indexOf(computer) !== 0) {
      $("#6").append("<p>" + computer + "</p>");
      $("#6").addClass("disabled");
      // test cases for winning combination [0, 4, 8] //    
    } else if ($("#0").text().indexOf("") === 0 && $("#0").text().indexOf(computer) !== 0 && $("#4").text().indexOf(player) >= 0 && $("#8").text().indexOf(player) >= 0) {
      $("#0").append("<p>" + computer + "</p>");
      $("#0").addClass("disabled");
    } else if ($("#0").text().indexOf(player) >= 0 && $("#4").text().indexOf("") === 0 && $("#4").text().indexOf(computer) !== 0 && $("#8").text().indexOf(player) >= 0) {
      $("#4").append("<p>" + computer + "</p>");
      $("#4").addClass("disabled");
    } else if ($("#0").text().indexOf(player) >= 0 && $("#4").text().indexOf(player) >= 0 && $("#8").text().indexOf("") === 0 && $("#8").text().indexOf(computer) !== 0) {
      $("#8").append("<p>" + computer + "</p>");
      $("#8").addClass("disabled");
    }

    // Priority 2: Prevent human from winning the game END //

    // Priority 3: Prevent human from creating forks BEGIN //
    else if ($("#0").text().indexOf(player) >= 0 && $("#8").text().indexOf(player) >= 0 && $("#1").text().indexOf(computer) !== 0 && $("#1").text().indexOf(player) !== 0) {
      $("#1").append("<p>" + computer + "</p>");
      $("#1").addClass("disabled");
    } else if ($("#2").text().indexOf(player) >= 0 && $("#6").text().indexOf(player) >= 0 && $("#1").text().indexOf(computer) !== 0 && $("#1").text().indexOf(computer) !== 0) {
      $("#1").append("<p>" + computer + "</p>");
      $("#1").addClass("disabled");
    }

    // Priority 3: Prevent human from creating forks END //

    // Priority 4: Choose an open space BEGIN //
    else if ($("#4").text().indexOf("") === 0 && $("#4").text().indexOf(player) !== 0 && $("#4").text().indexOf(computer) !== 0) {
      $("#4").append("<p>" + computer + "</p>");
      $("#4").addClass("disabled");
    } else if ($("#0").text().indexOf("") === 0 && $("#0").text().indexOf(player) !== 0 && $("#0").text().indexOf(computer) !== 0) {
      $("#0").append("<p>" + computer + "</p>");
      $("#0").addClass("disabled");
    } else if ($("#2").text().indexOf("") === 0 && $("#2").text().indexOf(player) !== 0 && $("#2").text().indexOf(computer) !== 0) {
      $("#2").append("<p>" + computer + "</p>");
      $("#2").addClass("disabled");
    } else if ($("#6").text().indexOf("") === 0 && $("#6").text().indexOf(player) !== 0 && $("#6").text().indexOf(computer) !== 0) {
      $("#6").append("<p>" + computer + "</p>");
      $("#6").addClass("disabled");
    } else if ($("#3").text().indexOf("") === 0 && $("#3").text().indexOf(player) !== 0 && $("#3").text().indexOf(computer) !== 0) {
      $("#3").append("<p>" + computer + "</p>");
      $("#3").addClass("disabled");
    } else if ($("#5").text().indexOf("") === 0 && $("#5").text().indexOf(player) !== 0 && $("#5").text().indexOf(computer) !== 0) {
      $("#5").append("<p>" + computer + "</p>");
      $("#5").addClass("disabled");
    } else if ($("#1").text().indexOf("") === 0 && $("#1").text().indexOf(player) !== 0 && $("#1").text().indexOf(computer) !== 0) {
      $("#1").append("<p>" + computer + "</p>");
      $("#1").addClass("disabled");
    } else if ($("#7").text().indexOf("") === 0 && $("#7").text().indexOf(player) !== 0 && $("#7").text().indexOf(computer) !== 0) {
      $("#7").append("<p>" + computer + "</p>");
      $("#7").addClass("disabled");
    } else if ($("#8").text().indexOf("") === 0 && $("#8").text().indexOf(player) !== 0 && $("#8").text().indexOf(computer) !== 0) {
      $("#8").append("<p>" + computer + "</p>");
      $("#8").addClass("disabled");
    }

    // Priority 4: Choose an open space END //

    //checkForWin();
  }

  function checkForWin() {
    if (turnCount >= 9) {
      endGame(2);
    }

    if ($("#0").text().indexOf(computer) >= 0 && $("#1").text().indexOf(computer) >= 0 && $("#2").text().indexOf(computer) >= 0) {
      endGame(1);
    } else if ($("#0").text().indexOf(player) >= 0 && $("#1").text().indexOf(player) >= 0 && $("#2").text().indexOf(player) >= 0) {
      endGame(0);
    } else if ($("#0").text().indexOf(computer) >= 0 && $("#4").text().indexOf(computer) >= 0 && $("#8").text().indexOf(computer) >= 0) {
      endGame(1);
    } else if ($("#0").text().indexOf(player) >= 0 && $("#4").text().indexOf(player) >= 0 && $("#8").text().indexOf(player) >= 0) {
      endGame(0);
    } else if ($("#0").text().indexOf(computer) >= 0 && $("#3").text().indexOf(computer) >= 0 && $("#6").text().indexOf(computer) >= 0) {
      endGame(1);
    } else if ($("#0").text().indexOf(player) >= 0 && $("#3").text().indexOf(player) >= 0 && $("#6").text().indexOf(player) >= 0) {
      endGame(0);
    } else if ($("#1").text().indexOf(computer) >= 0 && $("#4").text().indexOf(computer) >= 0 && $("#7").text().indexOf(computer) >= 0) {
      endGame(1);
    } else if ($("#1").text().indexOf(player) >= 0 && $("#4").text().indexOf(player) >= 0 && $("#7").text().indexOf(player) >= 0) {
      endGame(0);
    } else if ($("#2").text().indexOf(computer) >= 0 && $("#4").text().indexOf(computer) >= 0 && $("#6").text().indexOf(computer) >= 0) {
      endGame(1);
    } else if ($("#2").text().indexOf(player) >= 0 && $("#4").text().indexOf(player) >= 0 && $("#6").text().indexOf(player) >= 0) {
      endGame(0);
    } else if ($("#2").text().indexOf(computer) >= 0 && $("#5").text().indexOf(computer) >= 0 && $("#8").text().indexOf(computer) >= 0) {
      endGame(1);
    } else if ($("#2").text().indexOf(player) >= 0 && $("#5").text().indexOf(player) >= 0 && $("#8").text().indexOf(player) >= 0) {
      endGame(0);
    } else if ($("#3").text().indexOf(computer) >= 0 && $("#4").text().indexOf(computer) >= 0 && $("#5").text().indexOf(computer) >= 0) {
      endGame(1);
    } else if ($("#3").text().indexOf(player) >= 0 && $("#4").text().indexOf(player) >= 0 && $("#5").text().indexOf(player) >= 0) {
      endGame(0);
    } else if ($("#6").text().indexOf(computer) >= 0 && $("#7").text().indexOf(computer) >= 0 && $("#8").text().indexOf(computer) >= 0) {
      endGame(1);
    } else if ($("#6").text().indexOf(player) >= 0 && $("#7").text().indexOf(player) >= 0 && $("#8").text().indexOf(player) >= 0) {
      endGame(0);
    }
  };

  function endGame(winner) {
    for (var i = 0; i < squareNumber.length; i++) {
      console.log("#" + i);
      $("#" + i).addClass("disabled");
    }
    if (winner === 0) {
      result.innerHTML = "<p>You Win!</p>";
      newGame.style.display = "inline-block";
    } else if (winner === 1) {
      result.innerHTML = "<p>The Computer Wins!</p>";
      newGame.style.display = "inline-block";
    } else if (winner === 2) {
      result.innerHTML = "<p>Tie Game!</p>";
      newGame.style.display = "inline-block";
    }
  };

  function resetGame() {
    turnCount = 0;
    for (var i = 0; i < squareNumber.length; i++) {
      $("#" + i).text("");
      $("#" + i).removeClass("disabled");
    }
    $(".result").text("");
    newGame.style.display = "none";
  };
              
            
!
999px

Console