From db3757ecb21c15a214e3685d60a7b437206470e7 Mon Sep 17 00:00:00 2001 From: SandraBergstrom Date: Fri, 1 Dec 2023 13:48:09 +0100 Subject: [PATCH] toggle box click in boxCheck and robotosTurn --- assets/js/script.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/assets/js/script.js b/assets/js/script.js index b492510..8eb66a8 100644 --- a/assets/js/script.js +++ b/assets/js/script.js @@ -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(); @@ -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)); } \ No newline at end of file