From d0da85166d7fd3d750c3ad70e7e74778516220c9 Mon Sep 17 00:00:00 2001 From: abhiram-shaji <122574760+abhiram-shaji@users.noreply.github.com> Date: Mon, 11 Mar 2024 22:48:52 -0700 Subject: [PATCH 1/5] Fix sound button duplication error on victory --- app.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/app.js b/app.js index affd031..49d56eb 100644 --- a/app.js +++ b/app.js @@ -233,6 +233,8 @@ const checkWinner = () => { const winner_statement = document.getElementById("winner"); const audio = document.querySelector("audio"); + + if (res == "O") { if (gameMode == 1) winner_statement.innerText = "Player Won"; // Single player mode else winner_statement.innerText = "Player 1 Won"; // 2 player mode @@ -282,12 +284,15 @@ const checkWinner = () => { document.getElementById("draw1").innerText = temp5; document.getElementById("draw2").innerText = temp6; - if (loss1 == 1 || loss2 == 1 || draw1 == 1 || draw2 == 1) { //when the game ends, I create and add a button in the 'div-end-of-game' div - var btn = document.createElement("button"); - btn.className = "btn-sound"; - btn.innerHTML = ""; - btn.onclick = muteAudio; - document.getElementsByClassName("div-end-of-game")[0].appendChild(btn); + if (loss1 == 1 || loss2 == 1 || draw1 == 1 || draw2 == 1) { + // To check if the btn already exist + if (document.getElementsByClassName("btn-sound").length === 0) { + var btn = document.createElement("button"); + btn.className = "btn-sound"; + btn.innerHTML = ""; + btn.onclick = muteAudio; + document.getElementsByClassName("div-end-of-game")[0].appendChild(btn); + } } }; From 1750cb7e0868fda36f38d1dc248e370f3798b3de Mon Sep 17 00:00:00 2001 From: abhiram-shaji <122574760+abhiram-shaji@users.noreply.github.com> Date: Mon, 11 Mar 2024 22:54:52 -0700 Subject: [PATCH 2/5] Populated contributors html file --- contributors.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/contributors.html b/contributors.html index 0e1c9cd..e4edda9 100644 --- a/contributors.html +++ b/contributors.html @@ -25,10 +25,10 @@

- - - - + + + +
CTR NOCONTRIBUTOR NAMECONTRIBUTOR GITHUB IDNo OF CONTRIBUTIONS#132Abhiram Shaji@abhiram-shajiOne
From 0cc13af91ed3195310c6bfb2198ea2298e895a05 Mon Sep 17 00:00:00 2001 From: abhiram-shaji <122574760+abhiram-shaji@users.noreply.github.com> Date: Mon, 11 Mar 2024 22:55:50 -0700 Subject: [PATCH 3/5] Update contributors html --- contributors.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/contributors.html b/contributors.html index e4edda9..0e1c9cd 100644 --- a/contributors.html +++ b/contributors.html @@ -25,10 +25,10 @@

- - - - + + + +
#132Abhiram Shaji@abhiram-shajiOneCTR NOCONTRIBUTOR NAMECONTRIBUTOR GITHUB IDNo OF CONTRIBUTIONS
From c8746effaf533b20bad80c4d6af974bfff927322 Mon Sep 17 00:00:00 2001 From: abhiram-shaji <122574760+abhiram-shaji@users.noreply.github.com> Date: Mon, 11 Mar 2024 23:00:03 -0700 Subject: [PATCH 4/5] Create contributions md file --- CONTRIBUTIONS.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 CONTRIBUTIONS.md diff --git a/CONTRIBUTIONS.md b/CONTRIBUTIONS.md new file mode 100644 index 0000000..d1eb01f --- /dev/null +++ b/CONTRIBUTIONS.md @@ -0,0 +1,30 @@ +# Contribution Guidelines + +## Issue + +**Sound Button Duplication #132** + +If you win the game and undo the last move, then win again, the sound button duplicates itself. + +## Solution + +The solution involves modifying the `checkWinner` function to check if the sound button already exists before creating a new one. This prevents the duplication of the sound button. + +### Code Modification + +```javascript +const checkWinner = () => { + // Existing code... + + if (loss1 == 1 || loss2 == 1 || draw1 == 1 || draw2 == 1) { + // Check if the button already exists + if (!document.getElementById("btn-sound")) { + var btn = document.createElement("button"); + btn.id = "btn-sound"; + btn.className = "btn-sound"; + btn.innerHTML = ""; + btn.onclick = muteAudio; + document.getElementsByClassName("div-end-of-game")[0].appendChild(btn); + } + } +}; From 6022057f2e39fcd18e8a9a66117939257c40c3ef Mon Sep 17 00:00:00 2001 From: abhiram-shaji <122574760+abhiram-shaji@users.noreply.github.com> Date: Mon, 11 Mar 2024 23:09:01 -0700 Subject: [PATCH 5/5] Modify contributions md file --- CONTRIBUTIONS.md => CONTRIBUTING.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) rename CONTRIBUTIONS.md => CONTRIBUTING.md (78%) diff --git a/CONTRIBUTIONS.md b/CONTRIBUTING.md similarity index 78% rename from CONTRIBUTIONS.md rename to CONTRIBUTING.md index d1eb01f..695b1af 100644 --- a/CONTRIBUTIONS.md +++ b/CONTRIBUTING.md @@ -1,4 +1,4 @@ -# Contribution Guidelines +# Project Name : Tic-Tac-Toe ## Issue @@ -6,6 +6,8 @@ If you win the game and undo the last move, then win again, the sound button duplicates itself. +## Fork Repo Link : https://github.com/abhiram-shaji/tictactoe/tree/fix-sound-button-duplication + ## Solution The solution involves modifying the `checkWinner` function to check if the sound button already exists before creating a new one. This prevents the duplication of the sound button. @@ -28,3 +30,8 @@ const checkWinner = () => { } } }; +``` + +## Reflection + +With the help of this contribution the app no multiplies sound button upon winning and retrying the last move.