From 72579e7c761e75e6f8320ba175c3aae2600d5f59 Mon Sep 17 00:00:00 2001 From: lolabird Date: Wed, 27 Dec 2023 08:57:39 -0700 Subject: [PATCH] Add formatting to index.html, handle empty strings in CE and 0 with equals --- index.html | 4 ++++ script.js | 12 ++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/index.html b/index.html index ad94e22..a7383a1 100644 --- a/index.html +++ b/index.html @@ -13,18 +13,22 @@
0
+ + + + diff --git a/script.js b/script.js index d8d4494..98942ce 100644 --- a/script.js +++ b/script.js @@ -19,8 +19,12 @@ function displayToScreen() { screen.textContent = screen.textContent.slice(0, -1); if (!isNaN(screen.textContent.charAt(-2))) { - screen.textContent = screen.textContent.trimEnd() - } + screen.textContent = screen.textContent.trimEnd() + } + + if (screen.textContent === "") { + screen.textContent = "0" + } } else { if (this.className == "operator") { let screenContent = screen.textContent; @@ -43,7 +47,7 @@ function displayToScreen() { } else if (screen.textContent === "0" && this.className == "num") { screen.textContent = this.textContent; - } else { + } else if (this.className == "num") { screen.textContent += this.textContent; } } @@ -106,7 +110,7 @@ function Calculator(str) { b = +parts[2]; - if (a && !b) { + if ((a || a == "0") && !b) { return a; } if (isNaN(a) || isNaN(b)) {