Skip to content

Add solution for makeCalculator.js - #3073

Open
JuliaTr wants to merge 1 commit into
mate-academy:masterfrom
JuliaTr:develop
Open

Add solution for makeCalculator.js#3073
JuliaTr wants to merge 1 commit into
mate-academy:masterfrom
JuliaTr:develop

Conversation

@JuliaTr

@JuliaTr JuliaTr commented Jul 9, 2026

Copy link
Copy Markdown

Implemented solution for calculator, which covers objects, object methods, callback and closure concepts.

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review Summary

I am requesting changes because there is a critical functional issue in your operate method that breaks a core requirement of the task. The specification requires that add, subtract, multiply, and divide can be passed as callbacks to operate while still supporting chaining via this, but right now operate calls callback(arg) without binding the calculator as the context. This means that when you do something like calculator.operate(calculator.add, 10), the this inside add will not reliably refer to the calculator object, so the internal result may not be updated correctly and chaining from within those callbacks can fail. To fix this, update operate so that it invokes the callback with the calculator as its this value, for example: callback.call(this, arg) on the line where the callback is executed. Once this is corrected, your implementation will meet the requirement that the methods work both as normal chained calls and when passed as callbacks to operate. Overall, your structure, use of arithmetic assignment operators, and chaining design look solid; you mainly need to address this context-binding issue to fully satisfy the task. Keep going—this is a subtle but important JavaScript concept, and fixing it will strengthen your understanding of how this works in callbacks.


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Important

Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.

Tip

If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.

Caution

Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.

Footnotes

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Comment thread src/makeCalculator.js
Comment on lines +38 to +39
operate(callback, arg) {
callback(arg);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The current implementation callback(arg); in operate does not guarantee that this inside methods like add refers to the calculator object when they are passed as callbacks. This violates the requirement that add, subtract, multiply, divide are passed as callbacks to operate and that chaining via this works. Consider invoking the callback with the calculator as its context, for example using callback.call(this, arg).

@2pasha 2pasha left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

lgtm 🔥

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants