JavaScript Calculator bad tests

Hi Guys, i’m sure this gets asked a lot but i’ve tried searching and I can’t find an answer to my problem so i’m here for help.

I built my calculator using react + redux and hooks. It works fine, it does all the functions, and what it’s supposed to do, but I can’t seem to pass tests 11 and 12 (or 13 since 11 is duplicated) so i’d appreciate it if someone took a look at my code:

a quick run-through on how it works:
I have a container component and a button component,
they both pull id names and key symbols from a “library” object I built.
I have 3 states, currentKey, Input and Product, which are managed by redux.
all the calculations are done in the reducer, and I have an inputCorrect function to fix my inputs using regex which the reducer uses.

One of the errors says expected 10.5-5.5 to be 5 and not 145, when I run this test it is correct for me. so I added a console.log to my reducer to show what tests they run, and the tests does 150.5-5.5 instead of what it’s supposed to do.

On an unrelated note. the example calculator show “0” instead of “-” when you click it.

If I switch to the development version of React I see this error message for the decimal tests (11 and 12).

Uncaught TypeError: str.pop is not a function

Seeing as the last test is also a test using decimal numbers it is likely related to the first two errors. I would check the inputCorrect function to see what is causing this.

1 Like

You rock, that did it, I forgot i can’t run pop() on a string, so I did replace() instead and that did the trick. It’s too bad codepen doesn’t tell me I can’t run an operation like pop on a string. I’m curious though what is this react development version you speak of?

The CDN scripts come in two versions, production and development.

The production version will give less helpful error messages and it might also swallow some errors.

that is helpful to know! Thank you once again.

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