From dc49e65560a5164428c704e72f2939f44349246b Mon Sep 17 00:00:00 2001 From: lolabird Date: Tue, 26 Dec 2023 20:44:05 -0700 Subject: [PATCH] Add condition to check for existing operators on screen --- script.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/script.js b/script.js index 9f81223..677f22b 100644 --- a/script.js +++ b/script.js @@ -1,5 +1,6 @@ -const screen = document.querySelector(".screen") -const buttons = document.querySelectorAll("button") +const screen = document.querySelector(".screen"); +const buttons = document.querySelectorAll("button"); +const operators = ["+", "-", "*", "/"]; buttons.forEach((button) => { button.addEventListener ("click", displayToScreen); @@ -10,9 +11,21 @@ function displayToScreen() { if (this.className == "equal") { //equal } else if (this.className == "clear") { - //clear + //clear´ } else { - screen.textContent = this.textContent; + let screenContent = screen.textContent; + + if (this.className == "operator") { + for (let i = 0; i < screenContent.length; i++ ) { + if (operators.includes(screenContent[i])) { + //call calculator + console.log("An operator was pressed again") + break; + } + } + } + + screen.textContent += this.textContent; console.log("A button was pressed") }