I can’t seem to figure out the logic of letting users input 2 consecutive operators while preventing them to spam the operators. The logic I always come up is they will be able to spam the operators. To avoid confusion in the code, here’s where I’m working on:
I don’t think I’m the best person to help you with this - I’m still getting my head around React and I haven’t even started this project.
But I’ll have a go anyway.
It looks as if your code only accepts the first of two (or more) consecutive operators.
But, from reading the instructions, that seems like the opposite of what’s required.
From my understanding of the instructions, if the user enters two (or more) consecutive operators, then only the last (most recent) operator that’s entered should be used.
That also seems to be how the example app works on CodePen.
So, I think that, if the user enters consecutive operators, then your code should replace lastPressed with the new operator.
Obviously, the minus operator is an exception.
Based on the way that the example app works:
an operator followed by the minus sign followed by a number → all OK
an operator followed by the minus sign followed by an operator → just use the last operator (i.e. discard the previous operator and the minus sign).