Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solution #2599

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion src/makeCalculator.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,39 @@
* @return {object}
*/
function makeCalculator() {
// write code here
const calc = {
result: 0,

add(num) {
return calc.result + num;
Comment on lines +10 to +11

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The add method should update calc.result with the new value instead of just returning it. Change return calc.result + num; to calc.result += num; return this; to ensure the result is updated and the method is chainable.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The add method should update the result property of the calculator object. Change this line to calc.result += num; and return this to allow method chaining.

},

subtract(num) {
return calc.result - num;
Comment on lines +14 to +15

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The subtract method should update calc.result with the new value instead of just returning it. Change return calc.result - num; to calc.result -= num; return this; to ensure the result is updated and the method is chainable.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The subtract method should update the result property of the calculator object. Change this line to calc.result -= num; and return this to allow method chaining.

},

multiply(num) {
return calc.result * num;
Comment on lines +18 to +19

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The multiply method should update calc.result with the new value instead of just returning it. Change return calc.result * num; to calc.result *= num; return this; to ensure the result is updated and the method is chainable.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The multiply method should update the result property of the calculator object. Change this line to calc.result *= num; and return this to allow method chaining.

},

divide(num) {
return calc.result / num;
Comment on lines +22 to +23

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The divide method should update calc.result with the new value instead of just returning it. Change return calc.result / num; to calc.result /= num; return this; to ensure the result is updated and the method is chainable.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The divide method should update the result property of the calculator object. Change this line to calc.result /= num; and return this to allow method chaining.

},

reset() {
this.result = 0;

return this;
},

operate(callback, number) {
this.result = callback(number);
Comment on lines +32 to +33

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The operate method should apply the callback to the current result and the provided number. Change this.result = callback(number); to this.result = callback(this.result, number); to ensure the operation is performed correctly.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The operate method should apply the callback to both the current result and the provided number. Update this line to this.result = callback(this.result, number); to ensure the operation is performed correctly.


return this;
},
};

return calc;
}

module.exports = makeCalculator;