Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
36 lines (26 sloc) 698 Bytes
// click a square and have an x show up
// second click makes an O.
const squares = document.getElementsByClassName('square');
let turn = "X";
const playToken = (event) => {
if(isSquareFree()){
// set target's played attribute to true
event.target.setAttribute("data-played", "true");
// play turn, depending on who's turn it is
if (turn === "X") {
event.target.innerHTML = "X";
turn = "O";
} else {
event.target.innerHTML = "O";
turn = "X";
}
}
}
const isSquareFree = () => {
return event.target.getAttribute("data-played") === "false";
}
for (var i = 0; i < squares.length; i++) {
squares[i].addEventListener('click', (event) => {
playToken(event);
});
}