Hi all, just finish my react calculator, I made a calculator in the past with eval but I tryed to make this without eval and from the scartch not looking on other examples, please if you can review my code I will be glad.

And also I have a question about the logic requested for the calculator.

The thing is with this operation: 5 * - + 5. That the bundle says should be 10.

But to do that I should remove “*” and “-” when I hit “+”, thats how works the example. But is wise this logic? Shouldn’t remove the negative sign when I hit “+” that was the last sign? All calculators work that way? just asking before refactor that.

In this example when I hit the sum sign it deletes both, subtract and multiply sign, so 5 * - + 5 it becomes in 5 + 5. I don’t know if general calculators work that way. I tested a few that I have and all have different results:

Galculator from manjaro gives 25 (5*5) so takes the first operator that I hit.
On an old LG works just like the example, when I hit plus remove multiply and subtract .
edit: google gives -25.
And in another cellphone I got an error.

I’m trying the understand why and when should I remove which signs to fix my code.

Most ‘simple’ calculators I know delete previous operator after you press new one.

When you press ‘5 ±*/ 5’ only the last one is taken into account - ‘5 / 5’.

Normal behavior if you’d ask me.

Why?
I don’t know technical details, but I can see a lot of problems if done differently.

Example:

‘5 - / 5’

Okay, we substract 5 from 5, what should be divided by what after that?
We divide 0 / 0 or 5 / 0 or 0 / 5?
Or should we divide 5 by 5 first, then substract?
But sustract what? 0 - 5 or 5 - 0?

I hope that was helpful.

Only thing I know is minus/plus sign before second number.

Ex if you want to multiply 5 times -1 you press ‘5 * (-1)’ and it works
Don’t know if there are more exceptions.