Skip to content

Commit 2624222

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

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,18 @@ btns.forEach((btn) => {
107107
let result = eval(data.join(""));
108108
data = [];
109109
data.push(result);
110-
result === Infinity ? screen.innerText = "Math Error. Cannot divide by zero" : screen.innerText = result;
110+
divideByZero(screen, result)
111111
} catch (e) {
112112
screen.innerText = `${e.name} press AC`;
113113
}
114114
}
115115

116+
function divideByZero(display, outcome) {
117+
outcome === Infinity
118+
? (display.innerText = "Math Error. Cannot divide by zero")
119+
: (display.innerText = outcomet);
120+
}
121+
116122
if (buttonValue === "%") {
117123
screen.innerText = screen.innerText / 100;
118124
console.log("josué");

0 commit comments

Comments
 (0)