From 3d3818411ba5bbe6176c4f51fa7305a72b901b11 Mon Sep 17 00:00:00 2001 From: daisyzhang2024 Date: Mon, 6 Nov 2023 13:23:20 -0800 Subject: [PATCH] added cross mechanism to tic tac toe --- _posts/2023-10-24-Tic_tac_toe_game.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/_posts/2023-10-24-Tic_tac_toe_game.md b/_posts/2023-10-24-Tic_tac_toe_game.md index 3b9af26..75deb01 100644 --- a/_posts/2023-10-24-Tic_tac_toe_game.md +++ b/_posts/2023-10-24-Tic_tac_toe_game.md @@ -83,6 +83,13 @@ function checkScore() { allSquares.forEach(square => square.replaceWith(square.cloneNode(true))) return } + const crossWins = array.every(cell => + allSquares[cell].firstChild?.classList.contains('cross')) + if (crossWins) { + infoDisplay.textContent = "Cross Wins!" + allSquares.forEach(square => square.replaceWith(square.cloneNode(true))) + return + } })