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 id="pickASide" class="text-center" title="Pick Your Side">
  <p>X's or O's?</p>
</div>

<div class="container-fluid" id="theGame">
  <div class="row" id="is">
    <div class="col-xs-12 col-sm-2 col-md-2 col-lg-2 scoreboard text-center">
      <div class="row">
        <div class="score col-xs-6 col-sm-6 col-md-6 col-lg-6">
          <div class="">You
          </div>
          <!--Buttons-->
          <button class="o xo" id="X"></button>
          <div>
            <input id="xScore" class="xDisplay" readonly></div>
          <div>
            <!--Buttons-->
            <button class="" id="reset"><i class="fa fa-refresh"></i></button></div>
        </div>
        <div class="score col-xs-6 col-sm-6 col-md-6 col-lg-6">
          <div class="" id="nameHere">Enemy
          </div>
          <!--Buttons-->
          <button class="o ox" id="O"></button>
          <div>
            <input id="oScore" class="oDisplay" readonly></div>


        </div>
      </div>
    </div>
    <div class="col-xs-12 col-sm-2 col-md-2 col-lg-2 scoreboard text-center">
      <div id="btnGameStyle">
        <h4>Game Style</br></h4>
        <button class="btn-success btn" id="reg">Regular</button>
        <button class="btn-primary btn" id="tbb">Tom Brady Bunch</button>
      </div>
    </div>
    <div class="col-xs-12 col-sm-2 col-md-2 col-lg-2 scoreboard text-center hidden" id="story">
      <div>
        <h4>Tom Brady Bunch</br><small>Tic Tac Toe</small></h4></p>Tom deflated the bawls before this match, but he has never played Tic Tac Toe before. Needless to say, the game is rigged in your favor. Enjoy.
        <p>
          <h6><small>He owns the rights to his face, but this is art.</small></h6></p>
      </div>
    </div>
    <div class="col-xs-12 col-sm-8 col-md-6 col-lg-6">

      <div class="row" id="tic">
        <div class="display" id="tac">
          <div class="one free board toe" id="one" data-ani="1">
          </div>
          <div class="two free board toe" id="two" data-ani="2">
            <div class="displaytwo">
            </div>
          </div>
          <div class="three free board toe" id="three" data-ani="3">
            <div class="displaythree">
            </div>
          </div>
          <div class="four free board toe" id="four" data-ani="4">
            <div class="displayfour">
            </div>
          </div>
          <div class="five free board toe" id="five" data-ani="5">
            <div class="displayfive">
            </div>
          </div>
          <div class="six free board toe" id="six" data-ani="6">
            <div class="displaysix">
            </div>
          </div>
          <div class="seven free board toe" id="seven" data-ani="7">
            <div class="displayseven">
            </div>
          </div>
          <div class="eight free board toe" id="eight" data-ani="8">
            <div class="displayeight">
            </div>
          </div>
          <div class="nine free board toe" id="nine" data-ani="9">
          </div>
        </div>
      </div>
    </div>
  </div>
</div>


<div id="here"></div>
            
          
!
            
              .score div, .score button, .score input {
  margin: .125em;
}
#btnGameStyle button {
  margin: .5em;
}
#tic #tac .marker {font-size: 50px;
  color:red;
  position: relative;
  left: 22%;
}
#tic #tac .marker2 {font-size: 50px;
  color:green;
  position: relative;
  left: 20%;
  top: -10%;
}
#tic #tac .deflategateF {
  background: url("http://www.tranquilinc.com/wp-content/uploads/2016/04/6.png") center;
 background-size: 65px;
}
#tic #tac .deflategate {
  background: url("http://www.tranquilinc.com/wp-content/uploads/2016/04/10.png") center;
 background-size: 65px;
}
#theGame #is #tic #tac .face {
  background: url("http://www.tranquilinc.com/wp-content/uploads/2016/05/6.png") center;
 background-size: 65px;
}
#theGame #is #tic #tac .ball {
  background: url("http://www.tranquilinc.com/wp-content/uploads/2016/04/10.png") center;
 background-size: 65px;
}
#theGame #is #tic #tac .odd {
  background: #000;
}
#theGame #is #tic #tac .even {
  background: #FFF;
}
#tic #tac .toe {
  background: #80A4BE;
}
#two {
  background: url("http://www.tranquilinc.com/wp-content/uploads/2016/04/9.png") center;
 background-size: 65px;
}
#seven {
  background: url("http://www.tranquilinc.com/wp-content/uploads/2016/04/5.png") center;
 background-size: 65px;
}#nine {
  background: url("http://www.tranquilinc.com/wp-content/uploads/2016/04/1.png") center;
 background-size: 65px;
}#four {
  background: url("http://www.tranquilinc.com/wp-content/uploads/2016/04/2.png") center;
 background-size: 65px;
}#six {
  background: url("http://www.tranquilinc.com/wp-content/uploads/2016/04/3.png") center;
 background-size: 65px;
}#one {
  background: url("http://www.tranquilinc.com/wp-content/uploads/2016/04/4.png") center;
 background-size: 65px;
}#five {
  background: url("http://www.tranquilinc.com/wp-content/uploads/2016/05/6.png") center;
 background-size: 65px;
}#three {
  background: url("http://www.tranquilinc.com/wp-content/uploads/2016/04/7.png") center;
 background-size: 65px;
}#eight {
  background: url("http://www.tranquilinc.com/wp-content/uploads/2016/04/8-1.png") center;
 background-size: 65px;
}

.display {
  width: 201px;
  height: 201px;
  background: #689CCC;
  margin: auto;
  border: black 3px solid;
  border-radius: 4px;
}

div.one,
div.two,
div.three,
div.four,
div.five,
div.six,
div.seven,
div.eight,
div.nine {
  float: left;
  border: black 3px solid;
  width: 65px;
  height: 65px;
}

div.one.free:hover,
div.two.free:hover,
div.three.free:hover,
div.four.free:hover,
div.five.free:hover,
div.six.free:hover,
div.seven.free:hover,
div.eight.free:hover,
div.nine.free:hover {
  float: left;
  border: green 3px solid;
  width: 65px;
  height: 65px;
}

div.one.taken:hover,
div.two.taken:hover,
div.three.taken:hover,
div.four.taken:hover,
div.five.taken:hover,
div.six.taken:hover,
div.seven.taken:hover,
div.eight.taken:hover,
div.nine.taken:hover {
  float: left;
  border: red 3px solid;
  width: 65px;
  height: 65px;
}

button.o {
  background-color: #777;
  border-radius: 50%;
  margin: auto;
}



button.o.xo.active {
  background-color: #7f7;
  border-radius: 50%;
  margin: auto;
}

button.o.ox.active {
  background-color: #7f7;
  border-radius: 50%;
  margin: auto;
}
.active {
  background-color: red;
}

.scoreboard {
  width: 200px;
  background-color: #80A4BE;
  border-radius: 4px;
  border: black 3px solid;
  margin: 2em;
  padding: .5em;
}

input {
  width: 30px;
  height: 30px;
}
@media screen and (min-width: 490px) {
  #theGame #is #tic #tac .face {
  background: url("http://www.tranquilinc.com/wp-content/uploads/2016/05/6.png") center;
 background-size: 150px;
}
#theGame #is #tic #tac .ball {
  background: url("http://www.tranquilinc.com/wp-content/uploads/2016/04/10.png") center;
 background-size: 150px;
}
  #tic #tac .marker {font-size: 100px;
  color:red;
  position: relative;
  left: 30%;
}
#tic #tac .marker2 {font-size: 100px;
  color:green;
  position: relative;
  left: 25%;
  top: 0;
}
  #tic #tac .deflategateF {
  background: url("http://www.tranquilinc.com/wp-content/uploads/2016/04/6.png") center;
 background-size: 150px;
}
  #tic #tac .deflategate {
  background: url("http://www.tranquilinc.com/wp-content/uploads/2016/04/10.png") center;
 background-size: 150px;
}
  #two {
  background: url("http://www.tranquilinc.com/wp-content/uploads/2016/04/9.png") center;
 background-size: 150px;
}
#seven {
  background: url("http://www.tranquilinc.com/wp-content/uploads/2016/04/5.png") center;
 background-size: 150px;
}#nine {
  background: url("http://www.tranquilinc.com/wp-content/uploads/2016/04/1.png") center;
 background-size: 150px;
}#four {
  background: url("http://www.tranquilinc.com/wp-content/uploads/2016/04/2.png") center;
 background-size: 150px;
}#six {
  background: url("http://www.tranquilinc.com/wp-content/uploads/2016/04/3.png") center;
 background-size: 150px;
}#one {
  background: url("http://www.tranquilinc.com/wp-content/uploads/2016/04/4.png") center;
 background-size: 150px;
}#five {
  background: url("http://www.tranquilinc.com/wp-content/uploads/2016/05/6.png") center;
 background-size: 150px;
}#three {
  background: url("http://www.tranquilinc.com/wp-content/uploads/2016/04/7.png") center;
 background-size: 150px;
}#eight {
  background: url("http://www.tranquilinc.com/wp-content/uploads/2016/04/8-1.png") center;
 background-size: 150px;
}
  
.display {
  width: 456px;
  height: 456px;
  background: #689CCC;
  border: black 3px solid;
  border-radius: 4px;
  margin:1em;
}

div.one,
div.two,
div.three,
div.four,
div.five,
div.six,
div.seven,
div.eight,
div.nine {
  float: left;
  border: black 3px solid;
  width: 150px;
  height: 150px;
}

div.one.free:hover,
div.two.free:hover,
div.three.free:hover,
div.four.free:hover,
div.five.free:hover,
div.six.free:hover,
div.seven.free:hover,
div.eight.free:hover,
div.nine.free:hover {
  float: left;
  border: green 3px solid;
  width: 150px;
  height: 150px;
}

div.one.taken:hover,
div.two.taken:hover,
div.three.taken:hover,
div.four.taken:hover,
div.five.taken:hover,
div.six.taken:hover,
div.seven.taken:hover,
div.eight.taken:hover,
div.nine.taken:hover {
  float: left;
  border: red 3px solid;
  width: 150px;
  height: 150px;
}

button.o {
  background-color: #777;
  border-radius: 50%;
  margin: auto;
}


button.o.xo.active {
  background-color: #7f7;
  border-radius: 50%;
  margin: auto;
}

button.o.ox.active {
  background-color: #7f7;
  border-radius: 50%;
  margin: auto;
}

.active {
  background-color: red;
}

.scoreboard {
  background-color: #80A4BE;
  border-radius: 4px;
  border: black 3px solid;
  margin:1em;
}

input {
  width: 30px;
  height: 30px;
}
}
            
          
!
            
              // Starting at line 25 use the side arrows to close all the functions to read the notes better.
// Win state
win = "";
spawn = 1;
gameOver = 0;
victory = 0;
// Score Board
xScore = 0;
oScore = 0;
// Enemy Display/Player Display
enemy = "";
player = "";
numPl = "";
moves = 1;
games = 1;
bradyGame = 0;
// Board Numbers (is a temp array of numbers for game) 
boardNum = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"];
// Board Numbers
board = ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine"];
// Left over numbers for placemarkers
open = ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine"];
// Array of Move List
moveListPlayer = [];
moveListEnemy = [];
// first Move
function firstMove() {
  if (games % 2 === 0) {
    randomize();
  }
}
//Greetings, jQuery Boiler Plate
function pickASide() {
  $("#pickASide").dialog({
    resizable: false,
    height: 140,
    modal: true,
    buttons: {
      "X": function() {
        $(this).dialog("close");
        player = "<div class='marker'>X</div>"
        enemy = "<div class='marker2'>O</div>";
        $("#X").addClass("active");
        $("#X").html("X");
        $("#O").html("O");
      },
      "O": function() {
        $(this).dialog("close");
        player = "<div class='marker2'>O</div>";
        enemy = "<div class='marker'>X</div>";
        $("#X").addClass("active");
        $("#X").html("O");
        $("#O").html("X");
      }
    }
  });
};
// HardReset Button Function
function hardReset() {
  document.getElementById("one").innerHTML = "";
  document.getElementById("two").innerHTML = "";
  document.getElementById("three").innerHTML = "";
  document.getElementById("four").innerHTML = "";
  document.getElementById("five").innerHTML = "";
  document.getElementById("six").innerHTML = "";
  document.getElementById("seven").innerHTML = "";
  document.getElementById("eight").innerHTML = "";
  document.getElementById("nine").innerHTML = "";
  moves = 1;
  games = 1;
spawn = 1;
  if (!$("#one").hasClass("free") && $("#one").hasClass("taken")) {
    $("#one").addClass("free");
    $("#one").removeClass("taken");
  }
  if (!$("#two").hasClass("free") && $("#two").hasClass("taken")) {
    $("#two").addClass("free");
    $("#two").removeClass("taken");
  }
  if (!$("#three").hasClass("free") && $("#three").hasClass("taken")) {
    $("#three").addClass("free");
    $("#three").removeClass("taken");
  }
  if ((!$("#four").hasClass("free")) && $("#four").hasClass("taken")) {
    $("#four").addClass("free");
    $("#four").removeClass("taken");
  }
  if (!$("#five").hasClass("free") && $("#five").hasClass("taken")) {
    $("#five").addClass("free");
    $("#five").removeClass("taken");
  }
  if (!$("#six").hasClass("free") && $("#six").hasClass("taken")) {
    $("#six").addClass("free");
    $("#six").removeClass("taken");
  }
  if (!$("#seven").hasClass("free") && $("#seven").hasClass("taken")) {
    $("#seven").addClass("free");
    $("#seven").removeClass("taken");
  }
  if (!$("#eight").hasClass("free") && $("#eight").hasClass("taken")) {
    $("#eight").addClass("free");
    $("#eight").removeClass("taken");
  }
  if (!$("#nine").hasClass("free") && $("#nine").hasClass("taken")) {
    $("#nine").addClass("free");
    $("#nine").removeClass("taken");
  }
  $("#one").removeClass("deflategate");
  $("#one").removeClass("deflategateF");
  $("#nine").removeClass("deflategate");
  $("#nine").removeClass("deflategateF");
  $("#two").removeClass("deflategate");
  $("#two").removeClass("deflategateF");
  $("#three").removeClass("deflategate");
  $("#three").removeClass("deflategateF");
  $("#four").removeClass("deflategate");
  $("#four").removeClass("deflategateF");
  $("#five").removeClass("deflategate");
  $("#five").removeClass("deflategateF");
  $("#six").removeClass("deflategate");
  $("#six").removeClass("deflategateF");
  $("#seven").removeClass("deflategate");
  $("#seven").removeClass("deflategateF");
  $("#eight").removeClass("deflategate");
  $("#eight").removeClass("deflategateF");

  open = ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine"];
  moveListEnemy = [];
  moveListPlayer = [];
  win = "",
    xScore = 0,
    oScore = 0,
    $("#O").removeClass("active"),
    $("#X").removeClass("active"),
    $(".xDisplay").val(xScore),
    $(".oDisplay").val(oScore);

  pickASide();
}
// Soft Reset Button Function
function resetBoard() {
  document.getElementById("one").innerHTML = "";
  document.getElementById("two").innerHTML = "";
  document.getElementById("three").innerHTML = "";
  document.getElementById("four").innerHTML = "";
  document.getElementById("five").innerHTML = "";
  document.getElementById("six").innerHTML = "";
  document.getElementById("seven").innerHTML = "";
  document.getElementById("eight").innerHTML = "";
  document.getElementById("nine").innerHTML = "";
  moves = 1;
spawn = 1;
  if (!$("#one").hasClass("free") && $("#one").hasClass("taken")) {
    $("#one").addClass("free");
    $("#one").removeClass("taken");
  }
  if (!$("#two").hasClass("free") && $("#two").hasClass("taken")) {
    $("#two").addClass("free");
    $("#two").removeClass("taken");
  }
  if (!$("#three").hasClass("free") && $("#three").hasClass("taken")) {
    $("#three").addClass("free");
    $("#three").removeClass("taken");
  }
  if ((!$("#four").hasClass("free")) && $("#four").hasClass("taken")) {
    $("#four").addClass("free");
    $("#four").removeClass("taken");
  }
  if (!$("#five").hasClass("free") && $("#five").hasClass("taken")) {
    $("#five").addClass("free");
    $("#five").removeClass("taken");
  }
  if (!$("#six").hasClass("free") && $("#six").hasClass("taken")) {
    $("#six").addClass("free");
    $("#six").removeClass("taken");
  }
  if (!$("#seven").hasClass("free") && $("#seven").hasClass("taken")) {
    $("#seven").addClass("free");
    $("#seven").removeClass("taken");
  }
  if (!$("#eight").hasClass("free") && $("#eight").hasClass("taken")) {
    $("#eight").addClass("free");
    $("#eight").removeClass("taken");
  }
  if (!$("#nine").hasClass("free") && $("#nine").hasClass("taken")) {
    $("#nine").addClass("free");
    $("#nine").removeClass("taken");
  }
  open = ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine"];
  moveListEnemy = [];
  moveListPlayer = [];
}
// Condiditonals for the checkWinState
// Sets who won then calls checkWinState
function winState() {
  //Player Move list
  if (moveListPlayer.indexOf("one") > -1 && moveListPlayer.indexOf("two") > -1 && moveListPlayer.indexOf("three") > -1) {
    gameOver = 1;
    win = "X";
    checkWinState();
    resetBoard();
    firstMove();
  }
  else if (moveListPlayer.indexOf("four") > -1 && moveListPlayer.indexOf("five") > -1 && moveListPlayer.indexOf("six") > -1) {
    gameOver = 1;
    win = "X";
    checkWinState();
    resetBoard();
    firstMove();
  }
  else if (moveListPlayer.indexOf("seven") > -1 && moveListPlayer.indexOf("eight") > -1 && moveListPlayer.indexOf("nine") > -1) {
    gameOver = 1;
    win = "X";
    checkWinState();
    resetBoard();
    firstMove();
  }
  else if (moveListPlayer.indexOf("three") > -1 && moveListPlayer.indexOf("six") > -1 && moveListPlayer.indexOf("nine") > -1) {
    gameOver = 1;
    win = "X";
    checkWinState();
    resetBoard();
    firstMove();
  }
  else if (moveListPlayer.indexOf("two") > -1 && moveListPlayer.indexOf("five") > -1 && moveListPlayer.indexOf("eight") > -1) {
    gameOver = 1;
    win = "X";
    checkWinState();
    resetBoard();
    firstMove();
  }
  else if (moveListPlayer.indexOf("one") > -1 && moveListPlayer.indexOf("four") > -1 && moveListPlayer.indexOf("seven") > -1) {
    gameOver = 1;
    win = "X";
    checkWinState();
    resetBoard();
    firstMove();
  }
  else if (moveListPlayer.indexOf("one") > -1 && moveListPlayer.indexOf("five") > -1 && moveListPlayer.indexOf("nine") > -1) {
    gameOver = 1;
    win = "X";
    checkWinState();
    resetBoard();
    firstMove();
  }
  else if (moveListPlayer.indexOf("seven") > -1 && moveListPlayer.indexOf("five") > -1 && moveListPlayer.indexOf("three") > -1) {
    gameOver = 1;
    win = "X";
    checkWinState();
    resetBoard();
    firstMove();
  }
  //enemy move list start
  else if (moveListEnemy.indexOf("one") > -1 && moveListEnemy.indexOf("two") > -1 && moveListEnemy.indexOf("three") > -1) {
    loser();
    gameOver = 1;
    win = "O";
    checkWinState();
    resetBoard();
    firstMove();
  }
  else if (moveListEnemy.indexOf("four") > -1 && moveListEnemy.indexOf("five") > -1 && moveListEnemy.indexOf("six") > -1) {
    loser();
    gameOver = 1;
    win = "O";
    checkWinState();
    resetBoard();
    firstMove();
  }
  else if (moveListEnemy.indexOf("seven") > -1 && moveListEnemy.indexOf("eight") > -1 && moveListEnemy.indexOf("nine") > -1) {
    loser();
    gameOver = 1;
    win = "O";
    checkWinState();
    resetBoard();
    firstMove();
  }
  else if (moveListEnemy.indexOf("three") > -1 && moveListEnemy.indexOf("six") > -1 && moveListEnemy.indexOf("nine") > -1) {
    loser();
    gameOver = 1;
    win = "O";
    checkWinState();
    resetBoard();
    firstMove();
  }
  else if (moveListEnemy.indexOf("two") > -1 && moveListEnemy.indexOf("five") > -1 && moveListEnemy.indexOf("eight") > -1) {
    loser();
    gameOver = 1;
    win = "O";
    checkWinState();
    resetBoard();
    firstMove();
  }
  else if (moveListEnemy.indexOf("one") > -1 && moveListEnemy.indexOf("four") > -1 && moveListEnemy.indexOf("seven") > -1) {
    loser();
    gameOver = 1;
    win = "O";
    checkWinState();
    resetBoard();
    firstMove();
  }
  else if (moveListEnemy.indexOf("one") > -1 && moveListEnemy.indexOf("five") > -1 && moveListEnemy.indexOf("nine") > -1) {
    loser();
    gameOver = 1;
    win = "O";
    checkWinState();
    resetBoard();
    firstMove();
  }
  else if (moveListEnemy.indexOf("seven") > -1 && moveListEnemy.indexOf("five") > -1 && moveListEnemy.indexOf("three") > -1) {
    loser();
    gameOver = 1;
    win = "O";
    checkWinState();
    resetBoard();
    firstMove();
  }
 else if ($("#one").hasClass("taken") && $("#two").hasClass("taken") && $("#three").hasClass("taken") && $("#four").hasClass("taken") && $("#five").hasClass("taken") && $("#six").hasClass("taken") && $("#seven").hasClass("taken") && $("#eight").hasClass("taken") && $("#nine").hasClass("taken")) {
    games += 1;
    resetBoard();
    firstMove();
  } 
  else if (spawn === 0) {
    spawn = 1;
  }
  else if (spawn === 1) {
    randomize();
  }
}
// Checks to see who won and if the game is at its nine game max.
// Check Win State
var checkWinState = function() {
  if (win === "X") {
    xScore++;
    win = "";
    gameOver = 0;
    games += 1;
    $(".xDisplay").val(xScore);
    deflategate();
    if (xScore == 9) {
      win = "";
      if (victory === 0) {
        victory = 1;
      } else if (victory === 1) {
        victory = 0;
      }
      xScore = 0;
      oScore = 0;
      games = 1;
      $("#O").removeClass("active");
      $("#X").removeClass("active");
      $(".xDisplay").val(xScore);
      $(".oDisplay").val(oScore);
      hardReset();
      pickASide();
    }
  } else if (win === "O") {
    oScore++;
    win = "";
    gameOver = 0;
    games += 1;
    $(".oDisplay").val(oScore);
    if (oScore === 9) {
      win = "",
        xScore = 0,
        oScore = 0,
        games = 1;
      $("#O").removeClass("active"),
        $("#X").removeClass("active"),
        $(".xDisplay").val(xScore),
        $(".oDisplay").val(oScore),
        alert('Did Cpt. Deflategate get the best of you?'),
        hardReset();
      pickASide();
    }
  }
};
//When User Clicks the Board to place a marker
// This is the conditional to see if marker can be placed.
// Button Click on Board
function buttonGame() {
  if (player === "") {
    pickASide();
  } else {
    select = $(this).attr('id');
    if ($("#" + select).hasClass("free")) {
      moves += 1;
      $("#" + select).addClass("taken")
      $("#" + select).removeClass("free")
      playerMoves();
      spawn = 1;
      winState();
      
    }
  }
}
//Computers randomly generated move on the Board
// Computer Move (Randomize)
function randomize() {
  spawn = 0;
  moves += 1;
  var random = Math.floor(Math.random() * open.length);
  temp = open[random];
  num = open.indexOf(temp);
  remove = open.splice(num, 1);
  document.getElementById(temp).innerHTML = enemy;
  $("#" + temp).removeClass("free");
  $("#" + temp).addClass("taken");
  moveListEnemy.push(temp);
      winState();
};
//Player Move
//The Function to physically mark the Board.
function playerMoves() {
  document.getElementById(select).innerHTML = "<div class='center'>" + player + "</div>";
  moveListPlayer.push(select);
  opp = open.indexOf(select);
  show = open.splice(opp, 1);
};

//Tom Brady Version (Code Below)
// deflategate
function deflategate() {
  if (bradyGame === 1) {
    if (xScore === 1) {
      $("#seven").addClass("deflategate");
    }
    if (xScore === 2) {
      $("#nine").addClass("deflategate");
    }
    if (xScore === 3) {
      $("#four").addClass("deflategate");
    }
    if (xScore === 4) {
      $("#six").addClass("deflategate");
    }
    if (xScore === 5) {
      $("#one").addClass("deflategate");
    }
    if (xScore === 6) {
      $("#three").addClass("deflategate");
    }
    if (xScore === 7) {
      $("#eight").addClass("deflategate");
    }
    if (xScore === 8) {
      $("#two").addClass("deflategate");
    }
    if (xScore === 9) {
      $("#five").addClass("deflategate");
    }

  }
}
// deflategate toggle for game style buttons
function deflatToggle() {
  if (bradyGame === 1) {
    if (xScore === 1) {
      $("#seven").addClass("deflategate");
    }
    if (xScore === 2) {
      $("#seven").addClass("deflategate");
      $("#nine").addClass("deflategate");
    }
    if (xScore === 3) {
      $("#four").addClass("deflategate");
      $("#seven").addClass("deflategate");
      $("#nine").addClass("deflategate");
    }
    if (xScore === 4) {
      $("#six").addClass("deflategate");
      $("#four").addClass("deflategate");
      $("#seven").addClass("deflategate");
      $("#nine").addClass("deflategate");
    }
    if (xScore === 5) {
      $("#one").addClass("deflategate");
      $("#six").addClass("deflategate");
      $("#four").addClass("deflategate");
      $("#seven").addClass("deflategate");
      $("#nine").addClass("deflategate");
    }
    if (xScore === 6) {
      $("#three").addClass("deflategate");
      $("#one").addClass("deflategate");
      $("#six").addClass("deflategate");
      $("#four").addClass("deflategate");
      $("#seven").addClass("deflategate");
      $("#nine").addClass("deflategate");
    }
    if (xScore === 7) {
      $("#eight").addClass("deflategate");
      $("#three").addClass("deflategate");
      $("#one").addClass("deflategate");
      $("#six").addClass("deflategate");
      $("#four").addClass("deflategate");
      $("#seven").addClass("deflategate");
      $("#nine").addClass("deflategate");
    }
    if (xScore === 8) {
      $("#two").addClass("deflategate");
      $("#eight").addClass("deflategate");
      $("#three").addClass("deflategate");
      $("#one").addClass("deflategate");
      $("#six").addClass("deflategate");
      $("#four").addClass("deflategate");
      $("#seven").addClass("deflategate");
      $("#nine").addClass("deflategate");
    }
    if (xScore === 9) {
      $("#five").addClass("deflategate");
      $("#two").addClass("deflategate");
      $("#eight").addClass("deflategate");
      $("#three").addClass("deflategate");
      $("#one").addClass("deflategate");
      $("#six").addClass("deflategate");
      $("#four").addClass("deflategate");
      $("#seven").addClass("deflategate");
      $("#nine").addClass("deflategate");
    }

  } else if (bradyGame === 0) {
    if (xScore === 1) {
      $("#seven").removeClass("deflategate");
    }
    if (xScore === 2) {
      $("#seven").removeClass("deflategate");
      $("#nine").removeClass("deflategate");
    }
    if (xScore === 3) {
      $("#four").removeClass("deflategate");
      $("#seven").removeClass("deflategate");
      $("#nine").removeClass("deflategate");
    }
    if (xScore === 4) {
      $("#six").removeClass("deflategate");
      $("#four").removeClass("deflategate");
      $("#seven").removeClass("deflategate");
      $("#nine").removeClass("deflategate");
    }
    if (xScore === 5) {
      $("#one").removeClass("deflategate");
      $("#six").removeClass("deflategate");
      $("#four").removeClass("deflategate");
      $("#seven").removeClass("deflategate");
      $("#nine").removeClass("deflategate");
    }
    if (xScore === 6) {
      $("#three").removeClass("deflategate");
      $("#one").removeClass("deflategate");
      $("#six").removeClass("deflategate");
      $("#four").removeClass("deflategate");
      $("#seven").removeClass("deflategate");
      $("#nine").removeClass("deflategate");
    }
    if (xScore === 7) {
      $("#eight").removeClass("deflategate");
      $("#three").removeClass("deflategate");
      $("#one").removeClass("deflategate");
      $("#six").removeClass("deflategate");
      $("#four").removeClass("deflategate");
      $("#seven").removeClass("deflategate");
      $("#nine").removeClass("deflategate");
    }
    if (xScore === 8) {
      $("#two").removeClass("deflategate");
      $("#eight").removeClass("deflategate");
      $("#three").removeClass("deflategate");
      $("#one").removeClass("deflategate");
      $("#six").removeClass("deflategate");
      $("#four").removeClass("deflategate");
      $("#seven").removeClass("deflategate");
      $("#nine").removeClass("deflategate");
    }
    if (xScore === 9) {
      $("#five").removeClass("deflategate");
      $("#two").removeClass("deflategate");
      $("#eight").removeClass("deflategate");
      $("#three").removeClass("deflategate");
      $("#one").removeClass("deflategate");
      $("#six").removeClass("deflategate");
      $("#four").removeClass("deflategate");
      $("#seven").removeClass("deflategate");
      $("#nine").removeClass("deflategate");
    }

  }
}
// Regular or TBB Game
function bradyGameCheck() {
  if (bradyGame === 0) {
    if ($("#reg").hasClass("btn-primary")) {
      $("#reg").removeClass("btn-primary");
      $("#tbb").removeClass("btn-success");
      $("#reg").addClass("btn-success");
      $("#tbb").addClass("btn-primary");
      $(".board").addClass("toe");
      $("#story").addClass("hidden");
      $("#nameHere").html("Enemy");
    }
  } else if (bradyGame === 1) {
    if ($("#reg").hasClass("btn-success")) {
      $("#reg").removeClass("btn-success");
      $("#tbb").removeClass("btn-primary");
      $("#reg").addClass("btn-primary");
      $("#tbb").addClass("btn-success");
      $(".board").removeClass("toe");
      $("#story").removeClass("hidden");
      $("#nameHere").html("Brady");
    }
  }
}
//Lose Animation
function loser() {
  if (bradyGame === 1) {
    loserAnimationOne();
  } else if (bradyGame === 0) {
    loserAnimationTwo();
  }
}
//Tom Brady Loser Animation
function loserAnimationOne() {
  var x = 1;
  var z = setInterval(animation, 500);

  function animation() {
    if (x === 7) {
      clearInterval(z);
      $("#one").removeClass("ball");
      $("#three").removeClass("ball");
      $("#five").removeClass("ball");
      $("#seven").removeClass("ball");
      $("#nine").removeClass("ball");
      $("#two").removeClass("face");
      $("#four").removeClass("face");
      $("#six").removeClass("face");
      $("#eight").removeClass("face");
    } else {
      if (x % 2 === 0) {
        $("#one").addClass("ball");
        $("#three").addClass("ball");
        $("#five").addClass("ball");
        $("#seven").addClass("ball");
        $("#nine").addClass("ball");
        $("#two").addClass("face");
        $("#four").addClass("face");
        $("#six").addClass("face");
        $("#eight").addClass("face");

        $("#one").removeClass("face");
        $("#three").removeClass("face");
        $("#five").removeClass("face");
        $("#seven").removeClass("face");
        $("#nine").removeClass("face");
        $("#two").removeClass("ball");
        $("#four").removeClass("ball");
        $("#six").removeClass("ball");
        $("#eight").removeClass("ball");
      } else {
        $("#one").addClass("face");
        $("#three").addClass("face");
        $("#five").addClass("face");
        $("#seven").addClass("face");
        $("#nine").addClass("face");
        $("#two").addClass("ball");
        $("#four").addClass("ball");
        $("#six").addClass("ball");
        $("#eight").addClass("ball");

        $("#one").removeClass("ball");
        $("#three").removeClass("ball");
        $("#five").removeClass("ball");
        $("#seven").removeClass("ball");
        $("#nine").removeClass("ball");
        $("#two").removeClass("face");
        $("#four").removeClass("face");
        $("#six").removeClass("face");
        $("#eight").removeClass("face");
      }
      x++;
    }
  }
}
//Checker Board Loser Animation
function loserAnimationTwo() {
  var x = 1;
  var z = setInterval(animation, 500);

  function animation() {
    if (x === 7) {
      clearInterval(z);
      $("#one").removeClass("odd");
      $("#three").removeClass("odd");
      $("#five").removeClass("odd");
      $("#seven").removeClass("odd");
      $("#nine").removeClass("odd");
      $("#two").removeClass("even");
      $("#four").removeClass("even");
      $("#six").removeClass("even");
      $("#eight").removeClass("even");
    } else {
      if (x % 2 === 0) {
        $("#one").addClass("odd");
        $("#three").addClass("odd");
        $("#five").addClass("odd");
        $("#seven").addClass("odd");
        $("#nine").addClass("odd");
        $("#two").addClass("even");
        $("#four").addClass("even");
        $("#six").addClass("even");
        $("#eight").addClass("even");

        $("#one").removeClass("even");
        $("#three").removeClass("even");
        $("#five").removeClass("even");
        $("#seven").removeClass("even");
        $("#nine").removeClass("even");
        $("#two").removeClass("odd");
        $("#four").removeClass("odd");
        $("#six").removeClass("odd");
        $("#eight").removeClass("odd");
      } else {
        $("#one").addClass("even");
        $("#three").addClass("even");
        $("#five").addClass("even");
        $("#seven").addClass("even");
        $("#nine").addClass("even");
        $("#two").addClass("odd");
        $("#four").addClass("odd");
        $("#six").addClass("odd");
        $("#eight").addClass("odd");

        $("#one").removeClass("odd");
        $("#three").removeClass("odd");
        $("#five").removeClass("odd");
        $("#seven").removeClass("odd");
        $("#nine").removeClass("odd");
        $("#two").removeClass("even");
        $("#four").removeClass("even");
        $("#six").removeClass("even");
        $("#eight").removeClass("even");
      }
      x++;
    }
  }
}

//Calling of Functions
// Start of Document Ready
$("document").ready(function() {
  pickASide();
  // X Score Display Button
  $(".xDisplay").val(0);
  // O Score Display Button
  $(".oDisplay").val(0);
  // Reset Button
  $("#reset").on("click", function() {
    hardReset();
  });
  $(".board").on("click", buttonGame);
  // Game Style
  $("#reg").bind("click", function() {
    bradyGame = 0;
    deflatToggle();
    bradyGameCheck();
  });
  $("#tbb").bind("click", function() {
    bradyGame = 1;
    deflatToggle();
    bradyGameCheck();
  });
  // Twitter Button
  $("#twitter").on("click", function() {
    var quoteToTweet = "The Tom Brady Bunch Tic-Tac-Toe Challange";
    var linkToTweet = 'https://twitter.com/home?status=' + encodeURIComponent(quoteToTweet);
    window.open(linkToTweet, '_blank');

  });
})
            
          
!
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