Skip to content

Commit

Permalink
toggle box click in boxCheck and robotosTurn
Browse files Browse the repository at this point in the history
  • Loading branch information
SandraBergstrom committed Dec 1, 2023
1 parent 03e6bb6 commit db3757e
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions assets/js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ function boxCheck() {
currentPlayer = currentPlayer === "X" ? "O" : "X";
turnCounter++;
if(turnCounter < 9){
// make it impossible to click in any box
boxes.forEach((box) => box.removeEventListener("click", boxCheck));
// wait 2 seconds before playing
setTimeout(function () {
robotosTurn();
Expand All @@ -245,4 +247,6 @@ function robotosTurn() {
boxes[play].textContent = "O";
checkIfWin();
currentPlayer = currentPlayer === "O" ? "X" : "O";
// make it possible to click empty boxes again
boxes.forEach((box) => box.addEventListener("click", boxCheck));
}

0 comments on commit db3757e

Please sign in to comment.