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 : https://codepen.io/samobim/pen/NWrMbYy?editors=0110
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().
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