-
-
Save CarBen/6071561 to your computer and use it in GitHub Desktop.
This file contains hidden or 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>TIC TAC TOE</title> | |
<style> | |
td { | |
height: 100px; | |
width: 100px; | |
border-color: black; | |
border-width: 1px; | |
border-style: solid; | |
font-size: 90px; | |
line-height: 100px; | |
text-align: center; | |
} | |
/* | |
td.x { | |
background-color: red; | |
} | |
td.o { | |
background-color: blue; | |
} | |
*/ | |
</style> | |
</head> | |
<body> | |
<div> | |
It is <span id='turn'>x</span>'s turn. | |
</div> | |
<table> | |
<tr> | |
<td></td> | |
<td></td> | |
<td></td> | |
</tr> | |
<tr> | |
<td></td> | |
<td></td> | |
<td></td> | |
</tr> | |
<tr> | |
<td></td> | |
<td></td> | |
<td></td> | |
</tr> | |
</table> | |
<script type="text/javascript"> | |
var turn = 'x'; | |
var counter = 0; | |
var squares = document.querySelectorAll('td'); | |
while(counter < squares.length) { | |
squares[counter].addEventListener('click', function () { | |
if (this.className === '') { | |
this.className = turn; | |
this.innerText = turn; | |
if (turn === 'x') { | |
turn = 'o'; | |
} else if (turn === 'o') { | |
turn = 'x'; | |
} | |
document.querySelectorAll('span#turn')[0].innerText = turn; | |
} | |
}); | |
counter = counter + 1; | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment