Created
October 31, 2016 11:06
-
-
Save sarahzinger/4c73cb96cb78266f57ca8acfbbe9f3dc to your computer and use it in GitHub Desktop.
Exported from Popcode. Click to import: https://popcode.org/?gist=4c73cb96cb78266f57ca8acfbbe9f3dc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Page Title</title> | |
</head> | |
<body> | |
<h1>Tic Tac Toe</h1> | |
<h2 id="turn">Turn: X</h2> | |
<h3 id="winner"></h3> | |
<div> | |
<div class="row"> | |
<div id="1" class="box" onclick="select(this)"> | |
</div> | |
<div id="2" class="box" onclick="select(this)"> | |
</div> | |
<div id="3" class="box" onclick="select(this)"> | |
</div> | |
</div> | |
<div class="row"> | |
<div id="4" class="box" onclick="select(this)"> | |
</div> | |
<div id="5" class="box" onclick="select(this)"> | |
</div> | |
<div id="6" class="box" onclick="select(this)"> | |
</div> | |
</div> | |
<div class="row"> | |
<div id="7" class="box" onclick="select(this)"> | |
</div> | |
<div id="8" class="box" onclick="select(this)"> | |
</div> | |
<div id="9" class="box" onclick="select(this)"> | |
</div> | |
</div> | |
</div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var whoseTurnIsIt = "X"; | |
var turnsLeft = 9; | |
var select = function(box) { | |
var text = box.children[0]; | |
box.textContent = whoseTurnIsIt; | |
if(whoseTurnIsIt ==="X") { | |
whoseTurnIsIt = "O"; | |
} else { | |
whoseTurnIsIt = "X"; | |
} | |
var h2 = document.querySelector("#turn"); | |
h2.innerHTML = "Turn: " + whoseTurnIsIt; | |
turnsLeft--; | |
if(turnsLeft === 0){ | |
console.log("game over!"); | |
var h3 = document.querySelector("#winner"); | |
h3.innerHTML="No more squares!"; | |
} | |
}; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.row div { | |
display: inline-block; | |
vertical-align:top; | |
} | |
.box { | |
width: 100px; | |
height: 80px; | |
margin: 1px; | |
background-color: grey; | |
font-size: 300%; | |
text-align: center; | |
padding-top: 20px; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment