Front End - Calculator - Story 13

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

How should I implement this? I am kinda having a hard time understanding this and getting the story to pass.

@jordy can you please provide more context about the issue you’are trying to solve? :smile:

I would like to know how I should implement this user story. As in, can someone explain it to me in a simpler fashion as it is described in the challenge on what I am supposed to do. Perhaps with some random equation examples on how the calculator should handle them so I can better understand the purpose of the story. It is the only story that is a bit vague and the only one left for me to pass.

Can you post the link to the challenge?

Certainly
Challenge

If the user entered two (2) operators (+, *, or /), use the last operator entered. If the last operator entered was -, treat it as a negative sign and not as an operator.

e.g.,

5 + * 7 = 35 because 5 * 7 = 35
The second operator here is *.

5 * - 5 = -25 because 5 * -5 = -25
The second operator here is -.

I can tell you how I handled this part of the logic when I completed this project.
My overall strategy was to create a concatenating string from user input (evaluating whenever there was a complete expression).
Whenever consecutive operators were entered, the most recently entered operator would concatenate onto the string, replacing the previous operator.
The only exception is the minus/negative operator, which has to be handled slightly differently.

EXAMPLE INPUTS:

1+-     becomes 1-
1-+     1+
1*-     1*-
1-*     1*
1*+     1+
1*+*-   1*-
1*-/+   1+
1*+/-   1/-
1/+/-   1/-

My project is here if you want to have a look: https://codepen.io/igorgetmeabrain/full/OJgedWb

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