Build a JavaScript Calculator - i need your help!

Front End Libraries Projects - Build a JavaScript Calculator

Hello, i need your help guys , for some reasons my Calculator isn’t giving the right answer when i try to add numbers (regarding the addition only i didn’t do the others yet). not sure where is the bug .
In order to save you some time the Bug should be coming from one of this two functions : equal() or add()
If you try for example to do 2 +1 and then press = you’ll get the result 1
and if you do 3 + 5 you’ll get 5 , for some reasons it always gives me the sec number that i have entered instead of the right result!
Here’s the link to my CodePen :

Take a look at the saveHere value in state after it’s should be updated with first number of addition. This should give idea whether the issue lies in add() or equal().

i don’t understand what you trying to say

Make sure that saveHere value is actually changed when you press number and then +.

why is it not changing i’m so confused ? saveHere: this.state.saveHere + this.state.input
something wrong here?

Well, this does look okay. So the next step would be making sure it’s being executed and if not - what is the reason.

maybe it’s because of the condition hmm meh

someone help me for god sake where’s eveyrone !

You have a problem with “input” property in the state, sometimes it is int and sometimes it is string. Remember that “int + string = string”, 0 + “1” = “01”. Another issue I found is with parseInt function in add method

1 Like