Stuck on javascript calculator User Story #13

Hi everyone, hope you are well. I’ve been trying to solve the JavaScript calculator project but I’ve been stuck on User Story #13 for 2 days now so I’ve come here for some advice.

Here is my GitHub repo: GitHub - TomasJesus/JS-calculator: Javascript Calculator

The problem I’m having is with User Story #13 where it has to pass the tests:
5 * - 5 = -25 and 5 * - + 5 = 10. I can make the first one work but it never does the second one and throws some more errors (sometimes stops the US #9 from working too) as such the version in GitHub is the version where everything besides issue #13 works with no bugs (that I have discovered).

Can someone please give my some hints on what I’m doing wrong? I would greatly appreciate the help.

Edit: here is a live version of the calculator:

The first difficulty with user story 13 is that the “-” operator is overloaded. Depending on when the user enters the minus sign, it could be a negation operator or a subtraction operator. So, you’ll have to develop a way to determine what should be done when the user enters a minus sign. (No other operator is overloaded, so this is the only operator that you have to deal with in this way.)

On top of that, the second part of that test (the “5 * - + 5 = 10” part) is basically asking, “What happens when I put in another operator before I even enter the next number?” The test asserts that the new operator should overwrite the old one. In that test, the “*” will be interpreted as the multiplication operator, then the “-” should be interpreted as the negation operator (you’ll need to figure out why), and then the “+” should be interpreted as a new addition operator that will overwrite the previous multiplication operator. So, your calculator should ultimately interpret “5 * - + 5” as “5 + 5”. (Note also that the test wants the negation to be overwritten as well. You’ll need to somehow track that too.)

I also got stuck on this user story. Maybe my code will help?

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