From 1b9f3ea828be0353794d614627e9cd7d2a162978 Mon Sep 17 00:00:00 2001 From: lolabird Date: Tue, 7 Nov 2023 22:18:03 -0700 Subject: [PATCH] Move all messages to DOM and remove child divs in score --- index.html | 4 +--- script.js | 11 +++++------ 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/index.html b/index.html index e09f0c2..4c76930 100644 --- a/index.html +++ b/index.html @@ -17,9 +17,7 @@ -
-
You:
-
Compy:
+
diff --git a/script.js b/script.js index 0abab1c..56d7989 100644 --- a/script.js +++ b/script.js @@ -3,6 +3,7 @@ let pScore = 0; let cScore = 0; let ps; // Define the external variable for user's choice const buttons = document.querySelectorAll('button'); +const msg = document.querySelector("#msg"); buttons.forEach((button) => { @@ -64,14 +65,14 @@ function game() { switch (play) { case "player loses": cScore += 1; - console.log("You lose!", cs, " beats", ps, ". You: ", pScore, "Computer: ", cScore); + msg.textContent = "You lose! " + cs + " beats " + ps + ". You: " + pScore + " Computer: " + cScore; break; case "player wins": pScore += 1; - console.log("You Win!", ps, " beats", cs, ". You: ", pScore, "Computer: ", cScore); + msg.textContent = "You lose! " + ps + " beats " + cs + ". You: " + pScore + " Computer: " + cScore; break; default: - console.log("It's a tie!", " You: ", pScore, "Computer: ", cScore); + msg.textContent = "It's a tie! " + "You: " + pScore + " Computer: " + cScore; break; } } @@ -83,12 +84,10 @@ function game() { function endGame(){ - const msg = document.querySelector("#msg"); - const span = document.createElement("span"); let winner = (pScore > cScore) ? true : false; if (winner) { - msg.textContent = "You won the game " + pScore + " to " + cScore + "! Great job!" ; + msg.textContent = "You won the game " + pScore + " to " + cScore + "! Great job!"; } else { msg.textContent = "You lost the game " + pScore + " to " + cScore + ". Better luck next time!"; }