Skip to content

Instantly share code, notes, and snippets.

@nknapp
Created November 8, 2018 15:59
Show Gist options
  • Save nknapp/14a9adb3fd45331a39565dd34be7440a to your computer and use it in GitHub Desktop.
Save nknapp/14a9adb3fd45331a39565dd34be7440a to your computer and use it in GitHub Desktop.
Tic Tac Toe
<html>
<head>
<style>
h1 {
position: absolute;
display: block;
top: 50%;
left: 50%;
transform: rotate(30deg);
}
td {
height: 100px;
padding: 50px;
font-size: 400%;
}
</style>
</head>
<body>
<table border="1">
<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 x = 'X'
document.querySelectorAll('td').forEach((cell) => {
cell.addEventListener('click', () => {
cell.innerText = x
if (x === 'X') {
x = 'O'
} else {
x = 'X'
}
})
})
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment