I have been stuck on the last test requirement for the calculator project. I intended to use a similar approach to how a phone calculator would just disregard the latest operator inputs if it was followed by a non minus operator. However, the test will not pass even though I believe it to do the same thing. Here is the part of my code for this test
This prevents the user from typing in any more operators after two have been entered (another part of my code restricts things like ** , //, */, *+, etc)
Am I close to the right approach for this specific test? I feel it essentially does the job but I guess it wants to wait until calculation to disregard the previous operators. Any advice is welcomed, thanks in advance
Also after looking at it, I realize my solution would have issues if someone were to chain together equations. But, I just want to pass the simple 5*-+5 test.
I think we need to see all of your code before we can help figure out why you are having problems. The best would be for you to put it somewhere public and then give us a link.
I’m getting two tests that fail right now, test 9 and test 13.
Try the following:
1 + 2 + 3 + 4 + 5
Notice that when you enter the second plus sign, the number after the first plus sign disappears completely and you are just left with 1 +. And this pattern continues with each additional plus sign. Instead of keeping a running total, your calculator is just throwing away values every time you add a plus sign. This is why test 9 is failing.
I’m not sure why test 13 is failing. The tests say the expected answer is 10 and that’s what I get when I enter 5 * - + 5.
thank you for your reply. Test 9 worked before I started focusing my code to pass 13. I think I can get 9 back to working, but 13 is what is stumping me. I am also not sure why. I have heard that using React 18 isn’t always supported for the FCC tests, which is what I am using. I will continue to search for 13’s solution!