From 0c9eba4e4ce73daede78a463516361875e1037ed Mon Sep 17 00:00:00 2001 From: Ayoub hj Date: Sun, 15 Sep 2024 14:24:02 +0100 Subject: [PATCH] Update insertPlayer input to change turns --- script.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/script.js b/script.js index be4a714..c54c09b 100644 --- a/script.js +++ b/script.js @@ -1,6 +1,14 @@ function gameBoard() { let gameBoardArr = [[],[],[]]; - const insertPlayerInput = (player, posArr) => gameBoardArr[posArr[0]][posArr[1]] = player; + let player = "X"; + const insertPlayerInput = function(posArr) { + gameBoardArr[posArr[0]][posArr[1]] = player; + if (player === "X") { + player = "O"; + } else { + player = "X"; + } + }; const displayGameBoard = () => console.log(gameBoardArr); return { insertPlayerInput, displayGameBoard }; }