Tests won't pass: Javascript Calculator Using React

I’ve created the javascript calculator using React. For some reason, half of the tests don’t pass even though it functions like the stories want. I’d appreciate any advice/pointers. Thanks in advance! Here is my pen for reference: https://codepen.io/jennyunh/pen/abWrWVj

Make sure to read more than the first line of the error messages, there’s additional information below. For example here:

  1. At any time, pressing the clear button clears the input and output values, and returns the calculator to its initialized state; 0 should be shown in the element with the id of “display”

Element with with id=“display” should show 0 : expected ‘\n’ to equal ‘0’

You have an additional line break character there, because your div id="display has more in it than just the display value. Remove all that from the div and only keep the <h2>{this.state.display}</h2>. You also reset the display to an empty string instead of 0.

That’ll let you pass a few more tests. The remaining failing ones also tell you what’s wrong. For example, it’s possible to enter something like 5.5.5, so your decimal handler should check if there’s already a decimal point in a number. I also can’t enter 10.5, the calculator won’t let me enter the 0.

Just work through them step by step.

1 Like

This is very helpful, thank you!

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