css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

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="container center-block btn" id="gameBoard">

  <ul class="row" id="row1">
    <li>
      <span class="btn btn-primary marking marking0"></span>
    </li>
    <li>
      <span class="btn btn-primary marking arking1"></span>
    </li>
    <li>
      <span class="btn btn-primary marking marking2"></span>
    </li>

  </ul>

  <ul class="row" id="row2">
    <li>
      <span class="btn btn-primary marking marking3"></span>
    </li>
    <li>
      <span class="btn btn-primary marking marking4"></span>
    </li>
    <li>
      <span class="btn btn-primary marking marking5"></span>
    </li>

  </ul>

  <ul class="row" id="row3">
    <li>
      <span class="btn btn-primary marking marking6"></span>
    </li>
    <li>
      <span class="btn btn-primary marking marking7"></span>
    </li>
    <li>
      <span class="btn btn-primary marking marking8"></span>
    </li>

  </ul>


</div>

<div class="container">


  <!-- Modal -->
  <div class="modal" id="myModal" role="dialog">
    <div class="modal-dialog modal-lg">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">Pick a side!</h4>
        </div>
        <div class="modal-body">
          <p class="text-center" data-dismiss="modal">
            <span class="btn btn-danger" onclick="chooseTeamX()">X</span>
            <span class="btn btn-success" onclick="chooseTeamO()">O</span>
          </p>
        </div>

      </div>
    </div>
  </div>
</div>
            
          
!
            
              body {
  background-color: rgb(51, 204, 204);
}

#chooseTeam {
  background-color: white;
  margin-top: 10%;
  width: 80%;
  z-index: 1;
  margin-top: 5%;
}

p {
  font-size: 50px;
  color: rgb(51, 204, 204);
}

span {
  margin: 10px;
}

#gameBoard {
  background-color: white;
  height: 410px;
  width: 600px;
  margin-top: 10%;
}

.divider {}

ul {
  padding: 0px;
  list-style-type: none;
  margin-top: 20px;
}

li {
  display: inline;
  margin-left: -10px;
}

.marking {
  font-size: 50px;
  background-color: gray;
  width: 18%;
  height: 90px;
}
            
          
!
            
              $(document).ready(function() {
  $("#myModal").modal();
});

//The tic tac toe squares that are taken.
var pastMoves = [];
var gameRunning = false;

var userOnTeamX = false;
//Either "X" or "O"
var userMarking = "";
var robotMarking = "";

//Used to generate random number from 0-9, which represents the board
var max = 9;
var min = 0;

function chooseTeamX() {
  userMarking = "X";
  robotMarking = "0";
  userOnTeamX = true;
  userChoseTeam();
}

function chooseTeamO() {
  userMarking = "O";
  robotMarking = "X";
  userOnTeamX = false;
  userChoseTeam();
}

//Fadesout and deletes the div where the user chose a team.
function userChoseTeam() {

  gameStart();

}

function gameStart() {
  gameRunning = true;

  robotsMove();

 

}

//The robots "cheating" brain for moves :D
function robotsMove() {

  var squareNum = Math.floor(Math.random() * (max - min + 1)) + min;

  //Come up with a different number if the square is taken
  while (pastMoves.indexOf(squareNum) !== -1) {
    var squareNum = Math.floor(Math.random() * (max - min + 1)) + min;

    //All spots may be taken
    checkForGameover();

  }

  //Update pastMoves
  pastMoves.push(squareNum);

  //ENEMY FIRST
  var chooseSquare = ".marking" + squareNum;
  $(chooseSquare).text(robotMarking);

  pastMoves.push(squareNum);

  //Did the robot just win
  checkForGameover();

}

function usersMove() {

  //Pauses the code execution until the user has chosen a spot.
  var userClickedOption = true;
  
console.log("Running");
  //Waits for the user to selection a click option and update the board
  
    setInterval(function(){
    
      $(".marking0").on("click", function() {
      $(".marking0").text(userMarking);
      pastMoves.push(0);
      userClickedOption = false;
      console.log("CLICKED");
         
         
     }, 1000);
      
      
      
}

function checkForGameover() {

}
            
          
!
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.
Loading ..................

Console