Skip to content

Commit b29f987

Browse files
committed
feat(JS) refactor code by creating displayResult() to use it in if statement with condition buttonValue === =
1 parent 2624222 commit b29f987

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

index.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,8 @@ btns.forEach((btn) => {
105105
if (buttonValue === "=") {
106106
try {
107107
let result = eval(data.join(""));
108-
data = [];
109-
data.push(result);
110-
divideByZero(screen, result)
108+
displayResult(data, result);
109+
divideByZero(screen, result);
111110
} catch (e) {
112111
screen.innerText = `${e.name} press AC`;
113112
}
@@ -116,7 +115,12 @@ btns.forEach((btn) => {
116115
function divideByZero(display, outcome) {
117116
outcome === Infinity
118117
? (display.innerText = "Math Error. Cannot divide by zero")
119-
: (display.innerText = outcomet);
118+
: (display.innerText = outcome);
119+
}
120+
function displayResult(array, outcome) {
121+
array = [];
122+
array.push(outcome);
123+
120124
}
121125

122126
if (buttonValue === "%") {

0 commit comments

Comments
 (0)