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

              
                <head>
  <link rel="stylesheet" href="path/to/font-awesome/css/font-awesome.min.css">
</head>
<nav class="navbar navbar-default navbar-css">
  <div class="container-fluid">
    <div class="row">
      <button id="restart" class="navbar-brand"><i class="fa fa-repeat fa-3x" aria-hidden="true"></i></button>
    </div>
  </div>
</nav>
<div class="modal fade" tabindex="-1" role="dialog">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h1 class="modal-title">Lets play Tic-Tac-Toe!</h1>
      </div>
      <div class="modal-body">
        <h1>Pick a side!</h1>
        <div class="row">
          <button id="x" class="col-sm-6" data-dismiss="modal">X</button>
          <button id="o" class="col-sm-6" data-dismiss="modal">O</button>
        </div>
      </div>
    </div>
  </div>
</div>
<div class="modal-win fade" tabindex="-1" role="dialog">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h1 class="modal-title">You Win!!</h1>
      </div>
      <div class="modal-body">
        <h1>Play again?</h1>
        <div class="row">
          <button id="yes" class="col-sm-6" data-dismiss="modal">Yes</button>
          <button id="no" class="col-sm-6" data-dismiss="modal">No</button>
        </div>
      </div>
    </div>
  </div>
</div>
<div class="modal-lose fade" tabindex="-1" role="dialog">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h1 class="modal-title">You Lose...</h1>
      </div>
      <div class="modal-body">
        <h1>Play again?</h1>
        <div class="row">
          <button id="yes-lose" class="col-sm-6" data-dismiss="modal">Yes</button>
          <button id="no" class="col-sm-6" data-dismiss="modal">No</button>
        </div>
      </div>
    </div>
  </div>
</div>
<div class="container">
  <div class="col-sm-6 board col-sm-offset-3">
    <div class="container">
      <div class="row">
        <div class="col-sm-4 squares border-right border-bottom">
          <button id="1" class="x-or-o" value="1"></button>
        </div>
        <div class="col-sm-4 squares border-bottom">
          <button id="2" class="x-or-o" value="2"></button>
        </div>
        <div class="col-sm-4 squares border-left border-bottom">
          <button id="3" class="x-or-o" value="3"></button>
        </div>
      </div>
      <div class="row">
        <div class="col-sm-4 squares border-right border-bottom">
          <button id="4" class="x-or-o" value="4"></button>
        </div>
        <div class="col-sm-4 squares border-bottom">
          <button id="5" class="x-or-o" value="5"></button>
        </div>
        <div class="col-sm-4 squares border-left border-bottom">
          <button id="6" class="x-or-o" value="6"></button>
        </div>
      </div>
      <div class="row">
        <div class="col-sm-4 squares border-right">
          <button id="7" class="x-or-o" value="7"></button>
        </div>
        <div class="col-sm-4 squares">
          <button id="8" class="x-or-o" value="8"></button>
        </div>
        <div class="col-sm-4 squares border-left">
          <button id="9" class="x-or-o" value="9"></button>
        </div>
      </div>
    </div>
  </div>
              
            
!

CSS

              
                body {
 background-color: #D9CB9E;
}
button {
  background: none;
  border: none;
}
button:active,
button:focus {
  outline: none;
}
.navbar-css{
  background: none;
  border: none;
}
#restart{
  color: #2A2C2B;
  margin-left: 15px;
}
.modal-content {
  background-color: #D9CB9E;
  color: rgba(122,29,19,1);
  text-align: center;
  font-family: 'Indie Flower', cursive;
  margin-bottom: -350px;
}
.modal-win,
.modal-lose {
  position: relative;
  outline: none;
}
#x,
#o,
#yes,
#yes-lose,
#no {
  font-size: 100px;
  text-shadow: 5px 5px 8px #000; 
}
#x:active,
#o:active,
#yes:active,
#no:active {
  text-shadow: none;
}

.board {
  background-color: #2A2C2B;
  width: 528px;
  height: auto;
  border-radius: 20px;
  margin-bottom: 0;
  margin-top: 75px;
}
.squares {
  text-align: center;
  font-family: 'Indie Flower', cursive;
  line-height: 166px;
  padding-top: -20px;
  border-width: 10px;
  border-color: rgba(122,29,19,0.8);
  display: inline-block;
  width: 166px;
  height: 166px;
  margin: 0px 0px 0px 0px;
  padding: 0px;
}
.x-or-o{
  font-size: 150px;
  color: rgba(217,203,158,1);
  min-width: 150px;
  min-height: 150px;
}
.border-right{
  border-right-style: solid;
}
.border-left {
  border-left-style: solid;
}
.border-bottom {
  border-bottom-style: solid;
}
/* Modified slider from w3 schools */
.switch {
  position: relative;
  display: inline-block;
  width: 130px;
  margin-top: 20px;
  margin-bottom: 20px;
}

/* Hide default HTML checkbox */
.switch input {display:none;}

/* The slider */
.slider {
  position: relative;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #2A2C2B;
  -webkit-transition: .4s;
  transition: .4s;
}
.slider p{
  height: 50px;
  transition: margin-left .4s;
}
.slider p:before {
  position: absolute;
  content: 'EASY';
  font-size: 30px;
  margin-top: 7px;
  margin-left: -10px;
  color: #D9CB9E;
  -webkit-transition: .4s;
  transition: .4s;
}

input:checked + .slider p:before {
  content: "HARD";
  -webkit-transform: translateX(-48px);
  -ms-transform: translateX(-48px);
  transform: translateX(-48px);
}

.slider:before {
  position: absolute;
  content: "";
  height: 42px;
  width: 42px;
  left: 4px;
  bottom: 4px;
  background-color: #586967;
  -webkit-transition: .4s;
  transition: .4s;
}

input:checked + .slider {
  background-color: #7A1D13;
}

input:focus + .slider {
  box-shadow: 0 0 1px #7A1D13;
}

input:checked + .slider:before {
  -webkit-transform: translateX(80px);
  -ms-transform: translateX(80px);
  transform: translateX(80px);
}

/* Rounded sliders */
.slider.round {
  border-radius: 34px;
}

.slider.round:before {
  border-radius: 50%;
}
              
            
!

JS

              
                $(document).ready(function() {
  var watson = [];
  var user = [];
  var hard = false;
  var gamePiece = "";
  var watsonPiece = "";
  var positions = [1,2,3,4,5,6,7,8,9];
  var wins=[[1,2,3],[4,5,6],[7,8,9,],[1,4,7],[2,5,8],[3,6,9],[1,5,9],[3,5,7]];
  
  $(window).load(modal());

  function getRandom() {
    return Math.floor(Math.random() * (positions.length - 1)) + 1;
  }
  
  function checkWin(arr){
    var result=wins.filter(subarr=>subarr.every(num=>arr.indexOf(num)>-1));
    if (result.length > 0){
      return true;
    }
  }

  function watsonMove() {
    var position = getRandom();
    if (!user.includes(position) && !watson.includes(position)){
      watson.push(position);
      $(document.getElementById(position.toString())).text(watsonPiece);
      $(document.getElementById(position.toString())).prop("disabled",true);
    }else {
      watsonMove();
    }
  }

  function modal() {
    $('.modal').modal('show');
  }
  $(".x-or-o").click(function() {
    if (!watson.includes(Number($(this).val())) || !user.includes(Number($(this).val()))) {
      $(document.getElementById($(this).prop("disabled",true)))
      user.push(Number($(this).val()))
      $(this).text(gamePiece);
      if (checkWin(user)===true){
        $('.modal-win').modal('show');
        $('.modal-win').css("z-index", 1050);
      }else{
      watsonMove();
        if (checkWin(watson)===true){
          $('.modal-lose').modal('show');
          $('.modal-lose').css("z-index", 1060);
        }
      }
      console.log(watson,user)
    }
  });
  $("#x").click(function() {
    gamePiece = "X";
    watsonPiece = "O"
  });
  $("#o").click(function() {
    gamePiece = "O";
    watsonPiece = "X"
  });
  $("#yes").click(function() {
    watson = [];
    user = [];
    $(".x-or-o").empty();
    $(".x-or-o").prop("disabled",false);
    modal();
  });
  $("#yes-lose").click(function() {
    watson = [];
    user = [];
    $(".x-or-o").empty();
    $(".x-or-o").prop("disabled",false);
    modal();
  });
  $("#restart").click(function() {
    watson = [];
    user = [];
    $(".x-or-o").empty();
    $(".x-or-o").prop("disabled",false);
    modal();
  });
});
              
            
!
999px

Console