Stuck at Build a JavaScript Calculator

Tell us what’s happening:

I’ve been trying to troubleshoot but I’m having issues.


image

it works, but I don’t know where it wants the result to be displayed since it’s fine for the other tests. I tried switching their places but that made things worse; tried without one or the other, still not good.


image

^Same issue.

This one’s trickier because I can’t figure out how to compromise.
They want:

5*-+5=10
5*-5=-25

Don’t know how to make both work without cheesing it specifically for the test.
Tried the second one on Windows’ calculator and it does the same thing my calculator does, replaces the “*” with a “-”, so the result is 0.


image
^works

Before every test, I hit Clear. That’s my only theory on why the tests are coming out negative, they’re not clearing previous tests or doing it differently.
Any help or feedback is greatly appreciated, been stuck for a couple of days now and I’m out of ideas.
Thanks

Your code so far

Your browser information:

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

Challenge Information:

Front End Development Libraries Projects - Build a JavaScript Calculator

image

looks like it’s not hitting Clear after the “10.5-5.5” check

Do you have the code with a working click handler and one that just sets it to yes/error?


I don’t think you want to use input elements for the readouts. I assume the tests are looking at the text content of the elements (and not the value attribute).

1 Like

Changed the input element to a paragraph element

<form>
        <p id="display" style={{ color: "white" }} type="text">
          {result}
        </p>
        {/* shows result once = is hit */}
        <p id="displayFormula" style={{ color: "orange" }} type="text">
          {formula}
        </p>

That didn’t change anything, but thank you.

I don’t understand your first question. The click handler works as far as I can tell, at least when I’m individually testing the app. Something only breaks when the FCC Test Suite runs.
Thanks for the reply

Not sure why the code was like that for me but it is fixed now.


Did you read the note at the top of the challenge?

When I switch to the old render method your code passes all but one test and that one seems to be failing correctly.

The sequence “5 * - 5” = should produce an output of “-25” : expected ‘0’ to equal ‘-25’

Old render:

import ReactDOM from "react-dom";
ReactDOM.render(<App />, document.getElementById("root"));
1 Like

I’m actively working on it, maybe you caught a glimpse when I accidentally saved or it auto-saved (I don’t save when I tinker but something must’ve happened, maybe I unconsciously hit ctrl+s at some point), and had to find an old copy and restore it.


I'm very new to this, how do I downgrade?

Thanks!

Edit: nvm, figured it out, but thanks a million for that :pray:. It’s been driving me insane why it wouldn’t work

1 Like

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