Javascript calculator failing tests that seem to pass

Hi everyone - I’m wondering if anyone can help me work out why the automatic tests are failing my calculator on a few items which seem to be working.

https://codepen.io/jonohewitt/pen/PoWNmXq

#7 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”

#8 As I input numbers, I should be able to see my input in the element with the id of “display”

#9 The expression 3 + 5 * 6 - 2 / 4 should produce 32.5 or 11.5 as an answer, depending on the logic your calculator uses

#12 The expression “10.5 - 5.5” should produce an output of “5”

#14 The sequence “5 - 2 = / 2 =” should produce an output of “1.5”

#15 The expression “2 / 7” should produce an output number with at least 4 decimal places

The other failing tests make sense but I don’t know where it’s going wrong on the ones above since it seems to work as intended. Thanks for any help!

  • One of the assertion tests requires multiplying by a negative integer which I cannot do unless the negative integer is entered first.

  • I can’t enter .01 for example.

  • Are you using the right types like signed integer or float? So is the primary state of the display a char 0 or an int 0.

  • I don’t know why they all fail but that’s where I’d start looking.


edit
I’ve figured out that your string conversion isn’t 100% accurate. When I enter multiple operators, specifically 5+ then - , *, or / it concatenates the string 5 to itself resulting in 55 then another operator and the string 55 is concatenated to itself resulting in 5555.

Thank’s for looking at my project!

There are definitely a few points where the project fails, like the parts you’ve mentioned, where I can see that the outputs aren’t what is expected and it makes sense to fail. I’ll keep working on these parts.

I was trying to ask more specifically about the failure points I listed which seem to work well but are showing up as failing, for example the clearing the display button which seems to work as intended.

I’ll work on it a bit more tomorrow and see if I can get some progress. Thanks again

Okay I think I’ve addressed the other issues with the calculator and now it seems to be passing each one when I try out the test examples manually - but I’m still automatically passing only 8/16.

https://codepen.io/jonohewitt/pen/PoWNmXq

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