FCC: Javascript Calculator, User Story #13

Hello campers!

I am stuck in the challenge with the Javascript Calculator in which I try to solve with react: https://codepen.io/fotisoikonomou/pen/mdaJBmJ

Please don’t judge me for the style because I know it is terrible right now.
The thing is I cant pass User Story #13. I’ve spend hours and still I got no solution!

Please I would really appreciate if someone could help me out there!

Thank you

Currently your handleEquals() function is passing your statement into eval without consideration to the operator order. Eval will return an error when passing in something like 5 - * 5, so you need to implement some logic that considers the order of these operators. My first thought is that this may require picking apart expression before being evaluated and keeping track of the last pressed operator (unless it is "-").

2 Likes

gabei’s reply is spot on. Something that helped me when I was stuck on this specific test was considering how my iphone calculator handles this test. Just like gabei said, I noticed it cancelled out chaining operators unless the last one was a minus to preserve negative numbers. Also I was using react 18 and my test would not pass even when I got the logic correct. If you feel that the logic is 100% correct and it still is not passing, then consider downgrading to react 17.0.2.

could you please explain to me with a simple example?

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.