Javascript calculator - making it work

UPD: I gave made this work, cleaned up the possible bugs related to the data flows in react and now I am really intrigued by one single function of the Calculator: it does not perform division!

The rest such as clearAll, Decimal, addition, subtraction, equals all work perfectly, except the division. When I try to divide by a number, what I get is a ‘0’ in the answer section and then if I click on the ‘=’ ‘NaN’ is what I get as the result. I have tried converting the currentValue and nextValue that store values for performing this operation using parseFloat(), parseInt() etc but it does not seem to help.

Any ideas on how to get this moving?

Hello everyone,

I have been struggling with this challenge for a while. After following a handful of video tutorials and reading quite a few articles, I have managed to write something but it does not seem to work:

Strangely, console messages I get tell me that ‘expression’ and ‘answer’, one of the two states of the Calculator app, are undefined. However I defined them within the this.state of the App component earlier.

Any ideas on how to make this work?

Hi @Karajna!

I am having trouble seeing the calculator.

Remember to use the format this.state.propertyName. Alternatively, you could declare the property names using object destructuring inside the render method and before the return statement. Class methods referenced in the render method have to be written as this.methodName.

that’s right, it is not rendering and I am wondering why :slight_smile:

thank you very much. I am cleaning up the code bit by bit now, but your comment was definitely very helpful!