123

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <div class="conatiner-fluid">
  <div class="page-header">
    <h1>TIC-TAC-TOE</h1>
  </div>
  <br><br>
  <div class="row">
    <div id="box" class="col-md-6 col-md-offset-3 col-sm-6 col-sm-offset-3 col-lg-6 col-lg-offset-3">
      <div class="row">
        <div class="col-md-2 col-md-offset-3 col-sm-2 col-sm-offset-3 col-lg-2 col-lg-offset-3 cell" id="topleft"></div>
        <div class="col-md-2 col-sm-2 col-lg-2 cell" id="topmid"></div>
        <div class="col-md-2 col-sm-2 col-lg-2 cell" id="topright"></div>
      </div>
      <div class="row">
        <div class="col-md-2 col-md-offset-3 col-sm-2 col-sm-offset-3 col-lg-2 col-lg-offset-3 cell" id="midleft"></div>
        <div class="col-md-2 col-sm-2 col-lg-2 cell" id="midmid"></div>
        <div class="col-md-2 col-sm-2 col-lg-2 cell" id="midright"></div>
      </div>
      <div class="row">
        <div class="col-md-2 col-md-offset-3 col-sm-2 col-sm-offset-3 col-lg-2 col-lg-offset-3 cell" id="bottleft"></div>
        <div class="col-md-2 col-sm-2 col-lg-2 cell" id="bottmid"></div>
        <div class="col-md-2 col-sm-2 col-lg-2 cell" id="bottright"></div>
      </div>
      <div id="choose"></div>
    </div>
  </div>
</div>
            
          
!
            
              html {
  min-height: 100%;
}

body {
  background-image: url(https://4.bp.blogspot.com/-O-jq5-2O_yU/U-22AvexgYI/AAAAAAABH-E/W24dQqerwoE/s0/Minimal%2BWindows%2B8.1%2BRed_Ultra%2BHD.jpg);
  background-repeat: no-repeat;
  background-size: 100% 100%;
  text-align: center;
  font-family: 'Rakkas', cursive;
  perspective: 500px;
  margin: 0px;
  padding: 0px;
  overflow-x: hidden;
}

h1 {
  font-size: 100px;
  color: rgb(27, 97, 115);
  text-shadow: 3px 3px 2px white;
}

.page-header {
  border: none;
}

#XO {
  font-size: 40px;
  position: absolute;
  top: 0px;
  height: 100%;
  width: 100%;
  color: white;
  background: rgba(27, 97, 115, 0.7);
  border: 4px solid #8A3834;
  border-radius: 150px;
  transform-origin: center center;
  transition: transform 0.4s ease;
  text-shadow: 4px 4px 2px #8A3834;
  box-shadow: 5px 5px 5px black;
}

#XO button {
  transform-origin: 50% 0%;
  transition: transform 0.75s cubic-bezier(0.5, 3, 0.65, 0.45) 0.3s;
  border: 3px solid #8A3834;
  margin: 1px 1px 1px 1px;
  padding: 1px 12px 1px 6px;
  font-family: 'Black Ops One', cursive;
  color: #8A3834;
  background: rgba(27, 97, 115, 0.7);
  border-radius: 20px;
  text-shadow: 3px 3px 2px black;
}

#XO button:hover {
  transition: background-color: 0.15s ease 0s, transform 0.15s ease 0s;
  transition-delay: 0s, 0s;
  transform: rotateX(-20deg);
  color: rgba(27, 97, 115, 0.7);
  background: #8A3834;
  text-decoration: none;
  border-color: white;
}

button:focus,
button:active {
  outline: none;
}

.cell {
  background: rgba(138, 56, 52, 0.7);
  min-width: 120px;
  min-height: 100px;
  border: 2px solid rgb(27, 97, 115);
  color: rgb(27, 97, 115);
  font-family: 'Black Ops One', cursive;
  font-size: 60px;
  border-radius: 10px;
  text-shadow: 3px 3px 2px black;
}

#result {
  color: #c32a17;
  font-size: 100px;
  text-shadow: 4px 4px 1px white;
}
            
          
!
            
              var cells = {
  topleft: "",
  topmid: "",
  topright: "",
  midleft: "",
  midmid: "",
  midright: "",
  bottleft: "",
  bottmid: "",
  bottright: ""
};
var turn = "bot";
var totalMoves = 0;
var result = "";
var userSide = "";
var botSide = "";

$(document).ready(function() {
  setTimeout(function() {
    chooseXO();
  }, 1000);
});

$('.cell').on('click', function() {
  var choice = $(this).attr('id');
  if (cells[choice] === "" && totalMoves < 9) {
    totalMoves++;
    makeMove(choice);
    botMove();
  }
});

function chooseXO(x, y, z) {
  if (result === "botWon") {
    html = '<div id="XO"><p id="result">YOU LOST</p>CHOOSE YOUR SIDE<br><button id="X">X</button><button id="O">O</button></div>';
  } else if (result === "tied") {
    html = '<div id="XO"><p id="result">GAME TIED</p>CHOOSE YOUR SIDE<br><button id="X">X</button><button id="O">O</button></div>';
  } else {
    html = '<div id="XO"><p id="result">LETS PLAY</p>CHOOSE YOUR SIDE<br><button id="X">X</button><button id="O">O</button></div>';
  }
  $(html).hide().appendTo('#choose').slideDown("slow");

  $("#X").click(function() {
    $('#' + x).css("background", "rgba(138, 56, 52, 0.6)");
    $('#' + y).css("background", "rgba(138, 56, 52, 0.6)");
    $('#' + z).css("background", "rgba(138, 56, 52, 0.6)");
    $('#XO').slideUp("slow", function() {
      $('#XO').remove();
    });
    userSide = "x";
    botSide = "o";
    newGame();
  });

  $("#O").click(function() {
    $('#' + x).css("background", "rgba(138, 56, 52, 0.7)");
    $('#' + y).css("background", "rgba(138, 56, 52, 0.7)");
    $('#' + z).css("background", "rgba(138, 56, 52, 0.7)");
    $('#XO').slideUp("slow", function() {
      $('#XO').remove();
    });
    userSide = "o";
    botSide = "x";
    newGame();
  });
}

function makeMove(choice) {
  var cell = '#' + choice;
  if (turn === "bot") {
    cells[choice] = botSide;
    $('<p>' + botSide + '</p>').appendTo(cell);
    turn = "human";
  } else {
    cells[choice] = userSide;
    $('<p>' + userSide + '</p>').appendTo(cell);
    turn = "bot";
  }
}

function newGame() {
  cells = {
    topleft: "",
    topmid: "",
    topright: "",
    midleft: "",
    midmid: "",
    midright: "",
    bottleft: "",
    bottmid: "",
    bottright: ""
  };
  turn = "bot";
  totalMoves = 0;
  result = "";
  for (var cell in cells) {
    cell = '#' + cell;
    $(cell).empty();
  }
  $('.cell').css("pointer-events", "auto");
  botMove();
}

function showWin(x, y, z) {
  $('.cell').css("pointer-events", "none");
  $('#' + x).animate({
    backgroundColor: "#c32a17"
  }, 'slow');
  $('#' + y).animate({
    backgroundColor: "#c32a17"
  }, 'slow');
  $('#' + z).animate({
    backgroundColor: "#c32a17"
  }, 'slow');

  setTimeout(function() {
    chooseXO(x, y, z);
  }, 1000);
}

function botMove() {
  //first move
  if (totalMoves === 0) {
    var x = Math.floor((Math.random() * 3));
    var y = Math.floor((Math.random() * 3));
    var choices = [
      ["topleft", "topmid", "topright"],
      ["midleft", "midmid", "midright"],
      ["bottleft", "bottmid", "bottright"]
    ];
    var choice = choices[x][y];
    makeMove(choice);
  }
  //winning moves
  //top horizontal winning move
  else {
    if (cells.topleft === botSide && cells.topmid === botSide && cells.topright === "") {
      makeMove("topright");
      result = "botWon";
      showWin("topleft", "topmid", "topright");
    } else if (cells.topleft === botSide && cells.topmid === "" && cells.topright === botSide) {
      makeMove("topmid");
      result = "botWon";
      showWin("topleft", "topmid", "topright");
    } else if (cells.topleft === "" && cells.topmid === botSide && cells.topright === botSide) {
      makeMove("topleft");
      result = "botWon";
      showWin("topleft", "topmid", "topright");
    }
    //mid horizontal winning move
    else if (cells.midleft === botSide && cells.midmid === botSide && cells.midright === "") {
      makeMove("midright");
      result = "botWon";
      showWin("midleft", "midmid", "midright");
    } else if (cells.midleft === botSide && cells.midmid === "" && cells.midright === botSide) {
      makeMove("midmid");
      result = "botWon";
      showWin("midleft", "midmid", "midright");
    } else if (cells.midleft === "" && cells.midmid === botSide && cells.midright === botSide) {
      makeMove("midleft");
      result = "botWon";
      showWin("midleft", "midmid", "midright");
    }
    //bottom horizontal winning move
    else if (cells.bottleft === botSide && cells.bottmid === botSide && cells.bottright === "") {
      makeMove("bottright");
      result = "botWon";
      showWin("bottleft", "bottmid", "bottright");
    } else if (cells.bottleft === botSide && cells.bottmid === "" && cells.bottright === botSide) {
      makeMove("bottmid");
      result = "botWon";
      showWin("bottleft", "bottmid", "bottright");
    } else if (cells.bottleft === "" && cells.bottmid === botSide && cells.bottright === botSide) {
      makeMove("bottleft");
      result = "botWon";
      showWin("bottleft", "bottmid", "bottright");
    }
    //left vertical winning move
    else if (cells.topleft === botSide && cells.midleft === botSide && cells.bottleft === "") {
      makeMove("bottleft");
      result = "botWon";
      showWin("topleft", "midleft", "bottleft");
    } else if (cells.topleft === botSide && cells.midleft === "" && cells.bottleft === botSide) {
      makeMove("midleft");
      result = "botWon";
      showWin("topleft", "midleft", "bottleft");
    } else if (cells.topleft === "" && cells.midleft === botSide && cells.bottleft === botSide) {
      makeMove("topleft");
      result = "botWon";
      showWin("topleft", "midleft", "bottleft");
    }
    //mid vertical winning move
    else if (cells.topmid === botSide && cells.midmid === botSide && cells.bottmid === "") {
      makeMove("bottmid");
      result = "botWon";
      showWin("topmid", "midmid", "bottmid");
    } else if (cells.topmid === botSide && cells.midmid === "" && cells.bottmid === botSide) {
      makeMove("midmid");
      result = "botWon";
      showWin("topmid", "midmid", "bottmid");
    } else if (cells.topmid === "" && cells.midmid === botSide && cells.bottmid === botSide) {
      makeMove("topmid");
      result = "botWon";
      showWin("topmid", "midmid", "bottmid");
    }
    //right vertical winning move
    else if (cells.topright === botSide && cells.midright === botSide && cells.bottright === "") {
      makeMove("bottright");
      result = "botWon";
      showWin("topright", "midright", "bottright");
    } else if (cells.topright === botSide && cells.midright === "" && cells.bottright === botSide) {
      makeMove("midright");
      result = "botWon";
      showWin("topright", "midright", "bottright");
    } else if (cells.topright === "" && cells.midright === botSide && cells.bottright === botSide) {
      makeMove("topright");
      result = "botWon";
      showWin("topright", "midright", "bottright");
    }
    //left cross winning move
    else if (cells.topleft === botSide && cells.midmid === botSide && cells.bottright === "") {
      makeMove("bottright");
      result = "botWon";
      showWin("topleft", "midmid", "bottright");
    } else if (cells.topleft === botSide && cells.midmid === "" && cells.bottright === botSide) {
      makeMove("midmid");
      result = "botWon";
      showWin("topleft", "midmid", "bottright");
    } else if (cells.topleft === "" && cells.midmid === botSide && cells.bottright === botSide) {
      makeMove("topleft");
      result = "botWon";
      showWin("topleft", "midmid", "bottright");
    }
    //right cross winning move
    else if (cells.topright === botSide && cells.midmid === botSide && cells.bottleft === "") {
      makeMove("bottleft");
      result = "botWon";
      showWin("topright", "midmid", "bottleft");
    } else if (cells.topright === botSide && cells.midmid === "" && cells.bottleft === botSide) {
      makeMove("midmid");
      result = "botWon";
      showWin("topright", "midmid", "bottleft");
    } else if (cells.topright === "" && cells.midmid === botSide && cells.bottleft === botSide) {
      makeMove("topright");
      result = "botWon";
      showWin("topright", "midmid", "bottleft");
    }
    //blocking moves
    //top horizontal blocking move
    else if (cells.topleft === userSide && cells.topmid === userSide && cells.topright === "") {
      makeMove("topright");
    } else if (cells.topleft === userSide && cells.topmid === "" && cells.topright === userSide) {
      makeMove("topmid");
    } else if (cells.topleft === "" && cells.topmid === userSide && cells.topright === userSide) {
      makeMove("topleft");
    }

    //mid horizontal blocking move
    else if (cells.midleft === userSide && cells.midmid === userSide && cells.midright === "") {
      makeMove("midright");
    } else if (cells.midleft === userSide && cells.midmid === "" && cells.midright === userSide) {
      makeMove("midmid");
    } else if (cells.midleft === "" && cells.midmid === userSide && cells.midright === userSide) {
      makeMove("midleft");
    }
    //bottom horizontal blocking move
    else if (cells.bottleft === userSide && cells.bottmid === userSide && cells.bottright === "") {
      makeMove("bottright");
    } else if (cells.bottleft === userSide && cells.bottmid === "" && cells.bottright === userSide) {
      makeMove("bottmid");
    } else if (cells.bottleft === "" && cells.bottmid === userSide && cells.bottright === userSide) {
      makeMove("bottleft");
    }
    //left vertical blocking move
    else if (cells.topleft === userSide && cells.midleft === userSide && cells.bottleft === "") {
      makeMove("bottleft");
    } else if (cells.topleft === userSide && cells.midleft === "" && cells.bottleft === userSide) {
      makeMove("midleft");
    } else if (cells.topleft === "" && cells.midleft === userSide && cells.bottleft === userSide) {
      makeMove("topleft");
    }
    //mid vertical blocking move
    else if (cells.topmid === userSide && cells.midmid === userSide && cells.bottmid === "") {
      makeMove("bottmid");
    } else if (cells.topmid === userSide && cells.midmid === "" && cells.bottmid === userSide) {
      makeMove("midmid");
    } else if (cells.topmid === "" && cells.midmid === userSide && cells.bottmid === userSide) {
      makeMove("topmid");
    }
    //right vertical blocking move
    else if (cells.topright === userSide && cells.midright === userSide && cells.bottright === "") {
      makeMove("bottright");
    } else if (cells.topright === userSide && cells.midright === "" && cells.bottright === userSide) {
      makeMove("midright");
    } else if (cells.topright === "" && cells.midright === userSide && cells.bottright === userSide) {
      makeMove("topright");
    }
    //left cross blocking move
    else if (cells.topleft === userSide && cells.midmid === userSide && cells.bottright === "") {
      makeMove("bottright");
    } else if (cells.topleft === userSide && cells.midmid === "" && cells.bottright === userSide) {
      makeMove("midmid");
    } else if (cells.topleft === "" && cells.midmid === userSide && cells.bottright === userSide) {
      makeMove("topleft");
    }
    //right cross blocking move
    else if (cells.topright === userSide && cells.midmid === userSide && cells.bottleft === "") {
      makeMove("bottleft");
    } else if (cells.topright === userSide && cells.midmid === "" && cells.bottleft === userSide) {
      makeMove("midmid");
    } else if (cells.topright === "" && cells.midmid === userSide && cells.bottleft === userSide) {
      makeMove("topright");
    }
    //forking moves
    else if (cells.topmid === botSide && cells.bottleft === userSide && cells.topleft === "" && cells.topright === "" && cells.midmid === "") {
      makeMove("topleft");
    } else if (cells.topmid === botSide && cells.bottright === userSide && cells.topleft === "" && cells.topright === "" && cells.midmid === "") {
      makeMove("topright");
    } else if (cells.bottmid === botSide && cells.topleft === userSide && cells.bottleft === "" && cells.bottright === "" && cells.midmid === "") {
      makeMove("bottleft");
    } else if (cells.bottmid === botSide && cells.topright === userSide && cells.bottleft === "" && cells.bottright === "" && cells.midmid === "") {
      makeMove("bottright");
    } else if (cells.midleft === botSide && cells.topright === userSide && cells.bottleft === "" && cells.topleft === "" && cells.midmid === "") {
      makeMove("topleft");
    } else if (cells.midleft === botSide && cells.bottright === userSide && cells.bottleft === "" && cells.topleft === "" && cells.midmid === "") {
      makeMove("bottleft");
    } else if (cells.midright === botSide && cells.topleft === userSide && cells.bottright === "" && cells.topright === "" && cells.midmid === "") {
      makeMove("topright");
    } else if (cells.midright === botSide && cells.bottleft === userSide && cells.bottright === "" && cells.topright === "" && cells.midmid === "") {
      makeMove("bottright");
    } else if (cells.topleft === botSide && cells.bottleft === userSide && cells.topmid === "" && cells.topright === "") {
      makeMove("topright");
    } else if (cells.topleft === botSide && cells.topright === userSide && cells.midleft === "" && cells.bottleft === "") {
      makeMove("bottleft");
    } else if (cells.topright === botSide && cells.bottright === userSide && cells.topmid === "" && cells.topleft === "") {
      makeMove("topleft");
    } else if (cells.topright === botSide && cells.topleft === userSide && cells.midright === "" && cells.bottright === "") {
      makeMove("bottright");
    } else if (cells.bottright === botSide && cells.bottleft === userSide && cells.midright === "" && cells.toptright === "") {
      makeMove("topright");
    } else if (cells.bottright === botSide && cells.topright === userSide && cells.bottpmid === "" && cells.bottleft === "") {
      makeMove("bottleft");
    } else if (cells.bottleft === botSide && cells.topleft === userSide && cells.bottmid === "" && cells.bottright === "") {
      makeMove("bottright");
    } else if (cells.bottleft === botSide && cells.bottright === userSide && cells.midleft === "" && cells.topleft === "") {
      makeMove("topleft");
    } else if (cells.topleft === botSide && cells.bottright === userSide && cells.topmid === "" && cells.topright === "") {
      makeMove("topright");
    } else if (cells.topleft === botSide && cells.bottright === userSide && cells.midleft === "" && cells.bottleft === "") {
      makeMove("bottleft");
    } else if (cells.topright === botSide && cells.bottleft === userSide && cells.topmid === "" && cells.topleft === "") {
      makeMove("topleft");
    } else if (cells.topright === botSide && cells.bottleft === userSide && cells.midright === "" && cells.bottright === "") {
      makeMove("bottright");
    } else if (cells.bottleft === botSide && cells.topright === userSide && cells.midleft === "" && cells.topleft === "") {
      makeMove("topleft");
    } else if (cells.bottleft === botSide && cells.topright === userSide && cells.bottmid === "" && cells.bottright === "") {
      makeMove("bottright");
    } else if (cells.bottright === botSide && cells.topleft === userSide && cells.bottmid === "" && cells.bottleft === "") {
      makeMove("bottleft");
    } else if (cells.bottright === botSide && cells.topleft === userSide && cells.midright === "" && cells.topright === "") {
      makeMove("topright");
    } else if (cells.midmid === userSide && cells.topleft === botSide && cells.bottright === "" && ((cells.topmid === "" && cells.topright === "" && cells.midright === "") || (cells.midleft === "" && cells.bottleft === "" && cells.bottmid === ""))) {
      makeMove("bottright");
    } else if (cells.midmid === userSide && cells.bottright === botSide && cells.topleft === "" && ((cells.topmid === "" && cells.topright === "" && cells.midright === "") || (cells.midleft === "" && cells.bottleft === "" && cells.bottmid === ""))) {
      makeMove("topleft");
    } else if (cells.midmid === userSide && cells.topright === botSide && cells.bottleft === "" && ((cells.topmid === "" && cells.topleft === "" && cells.midleft === "") || (cells.midright === "" && cells.bottright === "" && cells.bottmid === ""))) {
      makeMove("bottleft");
    } else if (cells.midmid === userSide && cells.bottleft === botSide && cells.topright === "" && ((cells.topmid === "" && cells.topleft === "" && cells.midleft === "") || (cells.midright === "" && cells.bottright === "" && cells.bottmid === ""))) {
      makeMove("topright");
    } else if (cells.topmid === botSide && cells.midleft === botSide && cells.topright === "" && cells.bottleft === "" && cells.topleft === "") {
      makeMove("topleft");
    } else if (cells.topmid === botSide && cells.midright === botSide && cells.topleft === "" && cells.bottright === "" && cells.topright === "") {
      makeMove("topright");
    } else if (cells.bottmid === botSide && cells.midleft === botSide && cells.bottright === "" && cells.topleft === "" && cells.bottleft === "") {
      makeMove("bottleft");
    } else if (cells.bottmid === botSide && cells.midright === botSide && cells.bottleft === "" && cells.topright === "" && cells.bottright === "") {
      makeMove("bottright");

    } else if (cells.topmid === botSide && cells.topleft === userSide && cells.midmid === "" && cells.bottright === "") {
      makeMove("bottright");
    } else if (cells.topmid === botSide && cells.topright === userSide && cells.midmid === "" && cells.bottleft === "") {
      makeMove("bottleft");
    } else if (cells.bottmid === botSide && cells.bottleft === userSide && cells.midmid === "" && cells.topright === "") {
      makeMove("topright");
    } else if (cells.bottmid === botSide && cells.bottright === userSide && cells.midmid === "" && cells.topleft === "") {
      makeMove("topleft");
    } else if (cells.midleft === botSide && cells.bottleft === userSide && cells.midmid === "" && cells.topright === "") {
      makeMove("topright");
    } else if (cells.midleft === botSide && cells.topleft === userSide && cells.midmid === "" && cells.bottright === "") {
      makeMove("bottright");
    } else if (cells.midright === botSide && cells.bottright === userSide && cells.midmid === "" && cells.topleft === "") {
      makeMove("topleft");
    } else if (cells.midrigt === botSide && cells.topright === userSide && cells.midmid === "" && cells.bottleft === "") {
      makeMove("bottleft");
    } else if (cells.topmid === botSide && cells.bottmid === userSide && cells.midmid === "" && cells.midleft === "") {
      makeMove("midleft");
    } else if (cells.bottmid === botSide && cells.topmid === userSide && cells.midmid === "" && cells.midright === "") {
      makeMove("midright");
    } else if (cells.midleft === botSide && cells.midright === userSide && cells.midmid === "" && cells.topmid === "") {
      makeMove("topmid");
    } else if (cells.midright === botSide && cells.midleft === userSide && cells.midmid === "" && cells.bottmid === "") {
      makeMove("bottmid");
    }
    //center if empty
    else if (cells.midmid === "") {
      makeMove("midmid");
    }
    //opposite corners if empty
    else if (cells.topleft === userSide && cells.bottright === "") {
      makeMove("bottright");
    } else if (cells.topright === userSide && cells.bottleft === "") {
      makeMove("bottleft");
    } else if (cells.bottleft === userSide && cells.topright === "") {
      makeMove("topright");
    } else if (cells.bottright === userSide && cells.topleft === "") {
      makeMove("topleft");
    }
    //any corner if empty
    else if (cells.topleft === "" && cells.midright === userSide) {
      makeMove("topleft");
    } else if (cells.topright === "" && cells.bottmid === userSide) {
      makeMove("topright");
    } else if (cells.bottleft === "" && cells.topmid === userSide) {
      makeMove("bottleft");
    } else if (cells.bottright === "" && cells.midleft === userSide) {
      makeMove("bottright");
    }
    //any empty cell
    else if (cells.topmid === "") {
      makeMove("topmid");
    } else if (cells.midright === "") {
      makeMove("midright");
    } else if (cells.bottmid === "") {
      makeMove("bottmid");
    } else if (cells.midleft === "") {
      makeMove("midleft");
    }
  }
  totalMoves++;
  //tie condition
  if (totalMoves === 9 && result !== "botWon") {
    result = "tied";
    setTimeout(function() {
      chooseXO();
    }, 1000);
  }
  console.log(totalMoves);
}
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console