Skip to content

Commit

Permalink
ISSUE andrewagain#17 bug-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
elizabethhess0320 committed Nov 15, 2021
1 parent d223632 commit 775fb7c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
16 changes: 9 additions & 7 deletions src/logic/calculate.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,15 @@ export default function calculate(obj, buttonName) {
// return {};
// }

// no operation yet, but the user typed one

// The user hasn't typed a number yet, just save the operation
// ISSUE #17 - Error while double click in divide button (moved up check)
// ISSUE #39 - Error while double clicking on the multiply button after entering only one number (moved up check)
if (!obj.next) {
return { operation: buttonName };
}

// User pressed an operation button and there is an existing operation
if (obj.operation) {
// ISSUE #16 - Calculator makes the sum of the two previous numbers before multiplying
Expand Down Expand Up @@ -194,13 +203,6 @@ export default function calculate(obj, buttonName) {
}
}

// no operation yet, but the user typed one

// The user hasn't typed a number yet, just save the operation
if (!obj.next) {
return { operation: buttonName };
}

// save the operation and shift 'next' into 'total'
return {
total: obj.next,
Expand Down
3 changes: 1 addition & 2 deletions src/logic/calculate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ describe("calculate", function() {

test(["2", "÷", "x", "+", "-", "x"], {
total: "2",
operation: "-",
higherOrder: { next: null, operation: "x" },
operation: "x",
});
});

0 comments on commit 775fb7c

Please sign in to comment.