Skip to content

Instantly share code, notes, and snippets.

@gmelodie
Last active February 2, 2019 11:28
Show Gist options
  • Save gmelodie/54cf5b9c401ddb3f567065d5d15ed702 to your computer and use it in GitHub Desktop.
Save gmelodie/54cf5b9c401ddb3f567065d5d15ed702 to your computer and use it in GitHub Desktop.
Tic-tac-toe game without winner checking
<html>
<script type="text/javascript">
let ex = true;
let oh = false;
function gameFinished() {
return null;
// dunno what to put here yet
}
function computePlay(buttonId) {
let divId = "div_"+buttonId;
let playSymbol;
let winner;
// choose symbol according to who's playing
if (ex) {
playSymbol = 'X';
} else if (oh) {
playSymbol = 'O';
}
// insert symbol on the page
document.getElementById(divId).innerHTML = playSymbol;
// check if there's a winner
if (winner = gameFinished()) {
document.getElementById('winner_msg').innerHTML = winner + ' wins!';
}
// update players' turns
ex = !ex;
oh = !oh;
}
</script>
<h1> Tic-tac-toe </h1>
<!-- FORM WITH THE BUTTONS -->
<br>
<br>
<br>
<h3 id="winner_msg"></h3>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment