Calculator App - User Story #13


Here’s what I’ve built so far: calculator-app
It passes 15 out of 16 tests but I’m kinda stuck on the 13th.
I’m not asking for a straight answer but could use a little hint on how to approach this.

Hi there, I have looked into the code, and u did a nice job, the err that u have in ur testing is this *13. If 2 or more operators are entered consecutively, the operation performed should be the last operator entered*. So it is related the Operation, u can also tested in ur Calculator App, try to select multiple operator and it will crash.
There is many ways that u can solve this and I think one of them is create a useState of Operator so that it will always the last one. If my point are not clear enough, I can make it a lot clear …

1 Like

Hey, thanks for giving me a hand. Although I didn’t create a useState for Operator as you suggested, I still managed to make it work. It is a little messy but it’s functional. I’ve updated the codepen project and it would be great if you could take a look and give feedback.

In short:

  • added another if/else statement to handleNumber action
  • created new variable which takes second last element from the expression state
  • rewrote handleOperator action with few if/else statements that manipulate the expression state based on the last and secondLast element from its current state

Also, I’d love to see the solution you mentioned to have another point of view on this.

1 Like

Nice Job, alright I will try to create alternative solution to implement the idea that I had early, as they say,if the code works don’t touch it hhh

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