JS Calculator - 13th bug. Anyone solved?

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:

  1. 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!

:laughing: I just solved this problem for someone else! Here, check out this post, it might help:

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.