FCC calculator case

Good evening. Does anybody know how to write code for this test case for a calculator?

If 2 or more operators are entered consecutively, the operation performed should be the last operator entered (excluding the negative (-) sign.

If you look at the failing test you will see the following information:

“The sequence “5 * - 5” = should produce an output of “-25” : expected ‘25’ to equal ‘-25’”

This means the test tried the calculation 5 * -5 and was expecting the answer to be -25 but your calculator displayed 25 instead. So your calculator is accidentally removing the minus sign before 5.

How would you go about figuring out why this is happening?

Good evening well I’ve been trying to figure out why is it when I press 5* and then I try to press -5 it won’t display the negative operator.

What’s the first method called when you click on the +, -, *, or / button? That’s where I’d probably start looking. Use some console.log statements to help you see why it isn’t doing what it should do. You are using the same logic for all four of these buttons. I think you will need to make some exceptions for the - button.

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