Hey there!
I’m bulding a JS calculator and trying to past the FCC test on it. But the FCC test is showing this error:
If 2 or more operators are entered consecutively, the operation performed should be the last operator entered (excluding the negative (-) sign.
The sequence “5 * - 5” = should produce an output of “-25” : expected ‘-5’ to equal ‘-25’.
Here is my code: https://codepen.io/ulugbek/pen/KOmErL
Interesting enough, the FCC example has the same 13th bug right here: https://codepen.io/freeCodeCamp/full/wgGVVX
Anyone solved this issue? Please share your experiance.
Thanks!
I just solved this problem for someone else! Here, check out this post, it might help:
Guys, I’m almost through with my JS calc but for one minor problem. It’s with user story #13 which states:
13. If 2 or more operators are entered consecutively, the operation performed should be the last operator entered (excluding the negative (-) sign.
The sequence “5 * - 5” = should produce an output of “-25” : expected ‘0’ to equal ‘-25’ AssertionError: The sequence “5 * - 5” = should produce an output of “-25” : expected ‘0’ to equal ‘-25’
(excluding the negative (-) sign was not listed …
Also, loosely explain how your code works (mainly the part where the calculation happens [what function are we editing?]).
Here’s the logic of your code, as I see it working
enter 5
currentComputation === ‘5
’
enter *
currentComputation === ‘0
’
enter -
currentComputation === ‘0 -
’
enter 5
currentComputation === ‘0 - 5
’
And 0 - 5 === -5
Yes, I think I need to implement some logic to handle negative numbers.