Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
elizabethhess0320 committed Nov 15, 2021
1 parent 4b1ca17 commit 1b6c151
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/logic/operate.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import Big from "big.js";

export default function operate(numberOne, numberTwo, operation) {
const one = Big(numberOne || "0");
const two = Big(numberTwo || (operation === "÷" || operation === 'x' ? "1": "0")); //If dividing or multiplying, then 1 maintains current value in cases of null
const two = Big(
numberTwo || (operation === "÷" || operation === "x" ? "1" : "0"),
); //If dividing or multiplying, then 1 maintains current value in cases of null
if (operation === "+") {
return one.plus(two).toString();
}
Expand All @@ -13,7 +15,8 @@ export default function operate(numberOne, numberTwo, operation) {
return one.times(two).toString();
}
if (operation === "÷") {
if (two === "0") {
// ISSUE #77 & 105 - Error while dividing by zero
if (two.eq(0)) {
alert("Divide by 0 error");
return "0";
} else {
Expand Down

0 comments on commit 1b6c151

Please sign in to comment.