From ebbdf7cb7318eaef1a633041d90d20535441a621 Mon Sep 17 00:00:00 2001 From: lolabird Date: Tue, 7 Nov 2023 22:30:37 -0700 Subject: [PATCH] Add child divs back to score and dynamically add tally to divs --- index.html | 4 +++- script.js | 7 ++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index 4c76930..b1d7b72 100644 --- a/index.html +++ b/index.html @@ -17,7 +17,9 @@ -
+
+
You: 0
+
Compy: 0
diff --git a/script.js b/script.js index 56d7989..849fe4a 100644 --- a/script.js +++ b/script.js @@ -1,9 +1,12 @@ let pScore = 0; let cScore = 0; -let ps; // Define the external variable for user's choice +let ps; const buttons = document.querySelectorAll('button'); const msg = document.querySelector("#msg"); +const score = document.querySelector("#score"); +const player = document.querySelector("#player"); +const computer = document.querySelector("#computer"); buttons.forEach((button) => { @@ -65,10 +68,12 @@ function game() { switch (play) { case "player loses": cScore += 1; + computer.textContent = cScore; msg.textContent = "You lose! " + cs + " beats " + ps + ". You: " + pScore + " Computer: " + cScore; break; case "player wins": pScore += 1; + player.textContent = pScore; msg.textContent = "You lose! " + ps + " beats " + cs + ". You: " + pScore + " Computer: " + cScore; break; default: