Skip to content

Commit 5b9092e

Browse files
committed
feat(JS) add ternary operator to if statement with condtion buttonValue === = so as tto surface error when user divide by zero
1 parent c82a989 commit 5b9092e

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

index.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,11 @@ btns.forEach((btn) => {
105105
if (buttonValue === "=") {
106106
try {
107107
let result = eval(data.join(""));
108-
console.log(result);
109108
data = [];
110109
data.push(result);
111-
screen.innerText = result;
110+
result === Infinity ? screen.innerText = "Math Error. Cannot divide by zero" : screen.innerText = result;
112111
} catch (e) {
113-
screen.innerText = e.name;
112+
screen.innerText = `${e.name} press AC`;
114113
}
115114
}
116115

0 commit comments

Comments
 (0)