From dce94d7165b76ad564ad65a8f940e490628b756e Mon Sep 17 00:00:00 2001 From: lolabird Date: Tue, 26 Dec 2023 21:25:33 -0700 Subject: [PATCH] Call calculator from dipslayToScreen --- script.js | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/script.js b/script.js index 677f22b..387d912 100644 --- a/script.js +++ b/script.js @@ -9,7 +9,11 @@ buttons.forEach((button) => { function displayToScreen() { if (this.className == "equal") { - //equal + let calc = new Calculator; + + console.log(screen.textContent) + screen.textContent = calc.calculate(screen.textContent) + " "; + console.log(typeof(screen.textContent)) } else if (this.className == "clear") { //clear´ } else { @@ -24,15 +28,27 @@ function displayToScreen() { } } } - - screen.textContent += this.textContent; - console.log("A button was pressed") + if (screen.textContent === "0") { + screen.textContent = this.textContent + " "; + console.log("A button was pressed"); + } else { + screen.textContent += this.textContent + " "; + console.log("A button was pressed"); + } + } } -function Calculator(str) { +function clear () { + +} + + +function Calculator(str) { + console.log("Calculator has been called") + this.methods = { "-": (a, b) => (a - b), "+": (a, b) => (a + b),