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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

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

              
                
<body>
<div class="container text-center">
<a class="btn btn-primary" id="turnX">I Chose X</a>
<a class="btn btn-primary" id="turnO">I Chose O</a>
<div class="row">
<div class="col-xs-4 square" id="0"><span hidden>#</span></div>
<div class="col-xs-4 square" id="1"><span hidden>#</span></div>
<div class="col-xs-4 square" id="2"><span hidden>#</span></div>
</div>
<div class="row">
<div class="col-xs-4 square" id="3"><span hidden>#</span></div>
<div class="col-xs-4 square" id="4"><span hidden>#</span></div>
<div class="col-xs-4 square" id="5"><span hidden>#</span></div>
</div>
<div class="row">
<div class="col-xs-4 square" id="6"><span hidden>#</span></div>
<div class="col-xs-4 square" id="7"><span hidden>#</span></div>
<div class="col-xs-4 square" id="8"><span hidden>#</span></div>
</div>
</div>
<div class="text-center" id="Win"></div>
<div class="container text-center">
<div class = "btn btn-primary" id="reset">Reset</div>
<div>
</body>

              
            
!

CSS

              
                body{
	background:no-repeat center fixed;
	background-image:url("https://image.shutterstock.com/z/stock-vector-vector-seamless-abstract-pattern-with-cross-marks-and-circles-hand-painted-background-304485251.jpg");
	-webkit-background-size:cover;
	-o-background-size:cover;
	background-size:cover;
}

#Win{
	font-size:30px;
	text-shadow:1px 1px 2px black, 0 0 1em blue,0 0 0.2em blue;
	background:rgba(255,255,255,0.9);
  margin:0px auto;
  padding:0;
  width:800px;
}

.boks{
float:none;
margin:0 auto;
margin-top:5%;	
width:38%;
}

.square span{
	text-align:center;
	vertical-align:middle;
}

.square{
	width:100px;
	height:100px;
	border:1px solid black;
	font-size:600%;
	background:rgba(255,255,255,0.9);
	cursor:pointer;
}

              
            
!

JS

              
                $(document).ready(function(){
	
var turn = "X";

var marker = ["#","#","#","#","#","#","#","#","#"];

var computersChoice = 0;

var runGame = false;//Hou trek van wie se beurt dit is in die speletjie.

var count = 0;//Kyk hoeveel skuiwe is gemaak laat daar nie te vell skuiwe dear spleer of rekenaar gemaak word nie.
  
 $("#turnX").one("click",function(){
	$("#turnO").off();//As turnX geselekteer is dan is turnO onaktief.
	turn = "X";
	computersChoice = "O";
	$("#turnO").css("opacity",0.23);
   $('.square').click(function(){
	var slot = $(this).attr('id');
    playerTurn(turn,slot);	
  });
	});
	
$("#turnO").one("click",function(){
  $("#turnX").off("click");	
	turn = "O";
	computersChoice = "X";
	$("#turnX").css("opacity",0.23);
  $('.square').click(function(){
	var slot = $(this).attr('id');
    playerTurn(turn,slot);	
  });
	});	 

function computerTurn(){
	var taken = false;
	while(taken === false && count !== 5){
		var computersCalc = (Math.random()*10).toFixed();
		var move = $("#" + computersCalc).text();
		if(move === "#"){
			$("#" + computersCalc).text(computersChoice);
			taken = true;
			marker[computersCalc] = computersChoice;
		}
	}
}
  
  function playerTurn(whosTurn,id){
	  var blockInUse = $("#" + id).text();
	  if(blockInUse === "#"){
		  count++;//Hou trek van hoeveel beweegings was daar tussen die spleer en rekenaar op speletjie bord.
		  marker[id] = whosTurn;//Verwys na die posisie in arry turns = ["#"(index 0 id = "0"),"#"()index(1),"#","#","#","#","#","#","#"]. Sit die X of O index wat speler of rekeneaar click in turns array bv turns = ["X(Verander na X as die blookie gekies word in array eerste blookie bo lings index 0)","#","#","#","#","#","#","#","#",];.
		  $("#" + id).text(turn);
		  whoWins(marker,whosTurn);
		  if(runGame === false){
			  computerTurn();
			  whoWins(marker,computersChoice);
		  }
	  }
  }

  function whoWins(turnArray,playerMovement){
	 if(turnArray[0] === playerMovement && turnArray[1] === playerMovement && turnArray[2] === playerMovement){
		 runGame = true;//Speler of rekenaar wen dus hoef die rekenaar nie meer die loop te laat loop nie wen kondiesie is bepaal.
		 $("#Win").text("Player " + playerMovement  + " wins! (Top row across 0,1 and 2 spots)");
		 setTimeout(function(){
		location.reload(true);	
		},2000);
	 }else if(turnArray[2] === playerMovement && turnArray[4] === playerMovement && turnArray[6] === playerMovement){
		runGame = true;
		$("#Win").text("Player " + playerMovement + " Wins (Top row  across 2,5 and 6 spots)");
		setTimeout(function(){
		location.reload(true);	
		},2000);
	}
	else if(turnArray[0] === playerMovement && turnArray[3] === playerMovement && turnArray[6] === playerMovement){
		runGame = true;
		$("#Win").text("Player " + playerMovement + " Wins (Top row  down 0,3 and 6 spots)");
		setTimeout(function(){
		location.reload(true);	
		},2000);
	}
	else if(turnArray[0] === playerMovement && turnArray[4] === playerMovement && turnArray[8] === playerMovement){
		runGame = true;
		$("#Win").text("Player " + playerMovement + " Wins (Top row  across 0,4 and 8 spots)");
		setTimeout(function(){
		location.reload(true);	
		},2000);
	}
	else if(turnArray[3] === playerMovement && turnArray[4] === playerMovement && turnArray[5] === playerMovement){
		runGame = true;
		$("#Win").text("Player " + playerMovement + " Wins (Middle row  across 3,4 and 5 spots)");
		setTimeout(function(){
		location.reload(true);	
		},2000);
	}
	else if(turnArray[6] === playerMovement && turnArray[7] === playerMovement && turnArray[8] === playerMovement){
		runGame = true;
		$("#Win").text("Player " + playerMovement + " Wins (Bottom row  across 6,7 and 8 spots)");
		setTimeout(function(){
		location.reload(true);	
		},1000);
	}
	else if(turnArray[2] === playerMovement && turnArray[5] ===  playerMovement && turnArray[8] === playerMovement){
		runGame = true;
		$("#Win").text("Player " + playerMovement + " Wins (Top row  across 2,5 and 8 spots)");
		setTimeout(function(){
		location.reload(true);	
		},2000);
	}
	else if(turnArray[1] === playerMovement && turnArray[4] === playerMovement && turnArray[7] === playerMovement){
		runGame = true;
		$("#Win").text("Player " + playerMovement + " Wins (Top row bottom 1,4 and 7 spots)");
		setTimeout(function(){
		location.reload(true);	
		},2000);
	}
	else{
		runGame = false;//Niemand het nog gewen nie spel gaan aan vir die oomblik nog.
	}
	 
  }
  
  
  $("#reset").click(function(){
	location.reload(true);
	});
	
  

});
              
            
!
999px

Console