Help needed for Javascript Calculator

I’m stuck on this challenge. unable to pass two test cases. Test 11 and 13.
the link to my codesandbox is here: FCC Javascript Calculator
Please check out the solution in the above link and let me know where am I going wrong ?
Any hint, suggestion or solution would be highly appreciated.

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36.

Challenge: Build a JavaScript Calculator

Link to the challenge:

@kevinSmith @ilenia @miku86 is anyone online? I was wondering if I could get some help here.

I don’t know react, I can’t be of any help

I’m at work, but I took a quick look. I kept getting this error:

ReferenceError
clear is not defined
App
/src/App.jsx:33:22
  30 | <div onClick={allClear} className="padButton clear red" id="clear">
  31 |   AC
  32 | </div>
> 33 | <div onClick={clear} className="padButton c red" id="c">
     |              ^
  34 |   C
  35 | </div>
  36 | <div>

sorry for disturbing u at work. Please carry on with ur work and look at this code once you r free.

Nah, that’s cool, I like little breaks from what I’m doing. I’m just reminding you to be patient - these are all volunteers doing this in their free time. I know it’s frustrating, but be patient.

yeah right, I spent the whole day just to get that one regular expression correct. Still couldn’t do it yet.

When I look at the first failing test:

  1. When the decimal element is clicked, a “.” should append to the currently displayed value; two “.” in one number should not be accepted

An input of “5 . 5 . 5” should display 5.55 : expected ‘5.5.5’ to equal ‘5.55’ AssertionError: An input of “5 . 5 . 5” should display 5.55 : expected ‘5.5.5’ to equal ‘5.55’

I see that that is indeed the case. The test is trying to tell you what the problem is. Were you not understanding why the test is failing or did you understand that and can’t figure out how to solve it?

I understood the problem but I’m unable to implement it. I am able to make accept only one decimal point. for instance, 5…5 is not accepted but 5.5.5 is being accepted. As you can see I have created 2 display elements. One for expression and second for answer. I have set this for the answer display but since, its not working properly I haven’t added it to the expression display.
This is the first issue.
The second one is the 13th test where I’m unable to allow it to accept - sign if there more than 1 operators.

Well, I think you need to check the current number. If it already has a decimal, then you don’t add a decimal, perhaps exit that function early. Be aware that you may have a decimal in a number previously in the expression. You’ve got to either figure out a way to either grab the last number off your string, or keep track of the current “number” separately.

this is exactly what I have tried to do but couldn’t figure out a way. If I’m splitting it to create an array and then I can’t not join the expression again with the same operator.

it is solved now, thanks.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.