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-fluid well">
  <h1 class="text-center">Tick Tae Toe<h1>
</div>
<div class="container text-center">
  <button class="btn btn-primary" id="X"> X</button>&nbsp;&nbsp;
    <button class="btn btn-primary" id="O"> O</button>&nbsp;&nbsp;
  <button class="btn btn-danger" id="reset"> Reset</button>
    </div>
    <br>
<div class="container">
  <div class="row">
    <div class="col-sm-4"></div>
    <div class="col-sm-4 xyz b2">
      <div class="row">
          <button class="btn a1 abc" id="0">#</button>
        <button class="btn a1 abc" id="1">#</button>
        <button class="btn a1 abc" id="2">#</button>
      </div><!--inner row ends here-->
      
      <div class="row b1">
        <button class="btn a1 abc" id="3">#</button>
        <button class="btn a1 abc" id="4">#</button>
        <button class="btn a1 abc" id="5">#</button>
      </div><!--inner row ends here-->
      
      <div class="row b1">
        <button class="btn a1 abc" id="6">#</button>
        <button class="btn a1 abc" id="7">#</button>
        <button class="btn a1 abc" id="8">#</button>
      </div><!--inner row ends here-->
    </div>
    <div class="col-sm-4"></div>
  </div>
    </div>
            
          
!
            
              button{
  width:70px;
}
.abc{
  background-color:black;
  height:100px;
  width:100px;
}
.v1{
  border-left:medium #CC0000 solid;
  height:100px;
}
.hr1{
  border-top:medium #CC0000 solid;
  width:100px;
}
.xyz{
  margin-left:40px;
}
.a1{
  height:100px;
  width:100px;
  color:white;
  font-size:20px;
}
.b1{
  margin-top:3px;
}
.b2{
  background-color:blue;
  width:308px;
}


            
          
!
            
              $(document).ready(function(){
  var pturn="X";
  var cturn="O";
  var count=0;
  var turns=["#","#","#","#","#","#","#","#","#"];
  var gameOn=false;
  $("#O").click(function(){
    pturn="O";
    cturn="X";
    $("#X").attr("disabled", "disabled");
  });
  $("#X").click(function(){
    pturn="X";
    cturn="O";
    $("#O").attr("disabled", "disabled");
  });
  $("#reset").click(function(){
    reset();
  });
  function reset(){
    pturn="X";
    cturn="O";
    turns=["#","#","#","#","#","#","#","#","#"];
    $("#O").removeAttr("disabled");
    $("#X").removeAttr("disabled");
    $(".a1").text("#");
    count=0;
    gameOn=false;
  }
  function computerTurn(){
    var taken=false;
    while(taken===false && count!==5){
      var computersMove=(Math.random()*10).toFixed();
      var move=$("#"+computersMove).text();
      if(move==="#"){
        $("#"+computersMove).text(cturn);
        taken=true;
        turns[computersMove]=cturn;
      }
    }
  }
  function playerTurn(pturn,id){
    var spotTaken=$("#"+id).text();
    if(spotTaken==="#"){
      count++;
      turns[id]=pturn;
      $("#"+id).text(pturn);
      winCondition(turns,pturn);
      if(gameOn===false){
        computerTurn();
        winCondition(turns,cturn);
      }
    }
  }
 function winCondition(turnArray,currentTurn){
 if(turnArray[0]===currentTurn && turnArray[1]===currentTurn && turnArray[2]===currentTurn){
   gameOn=true;
   reset();
   alert("Player"+currentTurn+"wins(0,1,2)")
 }
   else if(turnArray[2]===currentTurn && turnArray[4]===currentTurn && turnArray[6]===currentTurn){
   gameOn=true;
   reset();
   alert("Player"+currentTurn+"wins(2,4,6)")
 }
   else if(turnArray[0]===currentTurn && turnArray[3]===currentTurn && turnArray[6]===currentTurn){
   gameOn=true;
   reset();
   alert("Player"+currentTurn+"wins(0,3,6)")
 }
   else if(turnArray[0]===currentTurn && turnArray[4]===currentTurn && turnArray[8]===currentTurn){
   gameOn=true;
   reset();
   alert("Player"+currentTurn+"wins(0,4,8)")
 }
   else if(turnArray[1]===currentTurn && turnArray[4]===currentTurn && turnArray[7]===currentTurn){
   gameOn=true;
   reset();
   alert("Player"+currentTurn+"wins(1,4,7)")
 }
   else if(turnArray[2]===currentTurn && turnArray[5]===currentTurn && turnArray[8]===currentTurn){
   gameOn=true;
   reset();
   alert("Player"+currentTurn+"wins(2,5,8)")
 }
   else if(turnArray[3]===currentTurn && turnArray[4]===currentTurn && turnArray[5]===currentTurn){
   gameOn=true;
   reset();
   alert("Player"+currentTurn+"wins(3,4,5)")
 }
   else if(turnArray[6]===currentTurn && turnArray[7]===currentTurn && turnArray[8]===currentTurn){
   gameOn=true;
   reset();
   alert("Player"+currentTurn+"wins(6,7,8)")
 }
   else{
     gameOn=false;
   }
  }
  $(".a1").click(function(){
    var slot=$(this).attr("id");
    playerTurn(pturn,slot);
  })
});
            
          
!
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