From f63ad42a364e16ab4aa8d903385c1441a7b65b92 Mon Sep 17 00:00:00 2001 From: lolabird Date: Wed, 27 Dec 2023 19:30:11 -0700 Subject: [PATCH] Fix mainScreen behavior --- script2.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/script2.js b/script2.js index 288064c..7fec622 100644 --- a/script2.js +++ b/script2.js @@ -52,6 +52,8 @@ function displayOperator() { topScreen.textContent += mainScreen.textContent; result = calc.calculate(topScreen.textContent); + + topScreen.textContent = result + " " + this.textContent + " "; } mainScreen.textContent = result; @@ -60,11 +62,16 @@ function displayOperator() { function displayNum() { - if (mainScreen.textContent == "0") { + if (mainScreen.textContent == "0" || inOps) { mainScreen.textContent = this.textContent; + inOps = false; } else { mainScreen.textContent += this.textContent; } + + if (isNaN(topScreen.textContent) && isNaN(topScreen.textContent.charAt(-1))) { + topScreen.textContent += this.textContent; + } }