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

Packages

Add 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 or require. We'll also process your JavaScript with Babel.

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

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.

Editor Settings

Code Indentation

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

Visit your global Editor Settings.

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.

            
              <!-- <!DOCTYPE html> -->
<html>

<head>
  <title>Tic Tac Toe</title>
  <link rel="stylesheet" href="css/index.css" type="text/css" />
  <link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.min.css" type="text/css" />
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" type="text/css" />
  <script type="text/javascript" src="bower_components/jquery/dist/jquery.min.js"></script>
  <script type="text/javascript" src="js/index.js"></script>

</head>

<body>
  <div class="spacer">TIC-TAC-TOE</div>
  <div class="gameboard" id="gameboard">

    <div class="row">
      <div class="square sq1"></div>
      <div class="square sq2"></div>
      <div class="square sq3"></div>
    </div>

    <div class="row">
      <div class="square sq4"></div>
      <div class="square sq5"></div>
      <div class="square sq6"></div>
    </div>

    <div class="row">
      <div class="square sq7"></div>
      <div class="square sq8"></div>
      <div class="square sq9"></div>
    </div>

  </div>

  <div class="spacer"></div>
  <div class="col-md-12 text-center" id="reload"><a href="#" class="btn btn-primary btn-lg">Reload Game?</a></div>
  <div class="col-md-12 text-center spacer" id="win">Player 1 has won the game!</div>
  <div class="col-md-12 text-center spacer" id="Scarlett">Scarlett has won :(</div>
</body>

</html>
            
          
!
            
              .gameboard {
  width: 372px;
  height: 372px;
  margin: auto;
}

.square {
  float: left;
  background: rgba(255, 255, 255, 0.9);
  width: 122px;
  height: 122px;
  border: 1px solid black;
  box-shadow: 8px 8px 15px #000;
  cursor: pointer;
  text-align: center;
  font-size: 100px;
}

.ex {
  background-color: white;
}

.oh {
  background-color: white;
}

body {
  background: no-repeat center center fixed;
  background: url("https://s19.postimg.cc/h85nh27ub/ninja_2-wallpaper-1366x768.jpg");
  background-size: cover;
}

.spacer {
  padding: 5%;
  text-align: center;
  text-shadow: 1px 1px 2px black, 0 0 1em black, 0 0 0.2em black;
  color: white;
  font: 3em;
}

.btn {
  box-shadow: 8px 8px 15px #000;
}

            
          
!
            
              $(document).ready(function() {
  var player = 1;
  var random = Math.floor(Math.random() * 9) + 1;
  var rand = Math.floor(Math.random() * 9) + 1;
  var tag = ".sq" + rand.toString();

  $("#reload").hide();
  $("#win").hide();
  $("#Scarlett").hide();

  $(".square").on("click", function(event) {
    var squareSelected = $(this);

    if (squareSelected.hasClass("ex") || squareSelected.hasClass("oh")) {
      alert("This square has been selected.");
    } else {
      if (player === 1) {
        squareSelected
          .addClass("ex")
          .append('<i class="fa fa-times" aria-hidden="true"></i>');
        if (didIWin("ex")) {
          $("#gameboard").hide();
          $("#reload").show();
          $("#win").show();
          $("#reload").click(function() {
            window.location.href = window.location.href;
          });
        } else if (tie()) {
           $("#gameboard").hide();
      $("#reload").show();
      $("#reload").click(function() {
        window.location.href = window.location.href;
      });
        } 
        else {
          player = 2;
          console.log(tag);
        }
      } else {
        $(randomSquare(random))
          .addClass("oh")
          .append('<i class="fa fa-circle-o" aria-hidden="true"></i>');
        if (didIWin("oh")) {
          // console.log("Tie");
          $("#gameboard").hide();
          $("#reload").show();
          $("#Scarlett").show();
          $("#reload").click(function() {
            window.location.href = window.location.href;
          });
        } else if (tie()) {
           $("#gameboard").hide();
      $("#reload").show();
      $("#reload").click(function() {
        window.location.href = window.location.href;
      });
        } 
         else {
          player = 1;
          console.log(tag);
        }
      }
    }
    
  });

  function tie() {
    if ($(".ex").length + $(".oh").length === 9) {
      if (didIWin(".ex") || didIWin(".oh")) {
        return false;
      } else {
        return true;
      }

     
    }
  }

  //   function tie(){
  //     var squareCount = didIWin()
  //     for (var tieCounter = 0; tieCounter<9; tieCounter++){
  //  if (squareCount += tieCounter){
  //    console.log("Its a tie");
  //  $("#gameboard").hide();
  //  $("#reload").show();
  //  $("#reload").click(function() {
  //  window.location.href = window.location.reload();
  //  });

  //  };
  //     }
  //   }

  //   function tie() {
  //   if (
  // $(".sq1").hasClass(symbol) &&
  // $(".sq2").hasClass(symbol) &&
  // $(".sq3").hasClass(symbol) &&
  // $(".sq4").hasClass(symbol) &&
  // $(".sq5").hasClass(symbol) &&
  // $(".sq6").hasClass(symbol) &&
  // $(".sq7").hasClass(symbol) &&
  // $(".sq8").hasClass(symbol) &&
  // $(".sq9").hasClass(symbol)
  // ) {
  // console.log("Its a tie");
  // $("#gameboard").hide();
  // $("#reload").show();
  // $("#reload").click(function() {
  // window.location.href = window.location.href;
  // });

  // }
  //   tie();
  // }

  // function tie() {
  //   if (random === 9) {
  //     console.log("Its a tie");
  //     $("#gameboard").hide();
  //     $("#reload").show();
  //     $("#reload").click(function() {
  //       window.location.href = window.location.href;
  //     });
  //   }
  // }

  function didIWin(symbol) {
    if (
      $(".sq1").hasClass(symbol) &&
      $(".sq2").hasClass(symbol) &&
      $(".sq3").hasClass(symbol)
    ) {
      return true;
    } else if (
      $(".sq4").hasClass(symbol) &&
      $(".sq5").hasClass(symbol) &&
      $(".sq6").hasClass(symbol)
    ) {
      return true;
    } else if (
      $(".sq7").hasClass(symbol) &&
      $(".sq8").hasClass(symbol) &&
      $(".sq9").hasClass(symbol)
    ) {
      return true;
    } else if (
      $(".sq1").hasClass(symbol) &&
      $(".sq4").hasClass(symbol) &&
      $(".sq7").hasClass(symbol)
    ) {
      return true;
    } else if (
      $(".sq2").hasClass(symbol) &&
      $(".sq5").hasClass(symbol) &&
      $(".sq8").hasClass(symbol)
    ) {
      return true;
    } else if (
      $(".sq3").hasClass(symbol) &&
      $(".sq6").hasClass(symbol) &&
      $(".sq9").hasClass(symbol)
    ) {
      return true;
    } else if (
      $(".sq1").hasClass(symbol) &&
      $(".sq5").hasClass(symbol) &&
      $(".sq9").hasClass(symbol)
    ) {
      return true;
    } else if (
      $(".sq7").hasClass(symbol) &&
      $(".sq5").hasClass(symbol) &&
      $(".sq3").hasClass(symbol)
    ) {
      return true;
    } else {
      return false;
    }
  }

  function randomSquare(rand) {
    while ($(tag).hasClass("ex") || $(tag).hasClass("oh")) {
      rand = Math.floor(Math.random() * 9) + 1;
      tag = ".sq" + rand.toString();
    }
    return tag;
  }
});

            
          
!
999px

Console