Tests failing on JS calculator, but everything works properly when I do it manually

Challenges 11 & 12 of the Javascript Calculator project both deal with decimals. They state that your calculator should not

  • Allow users to input a decimal more than once on a given integer
  • Fail to calculate any function that includes decimals.

When I run the tests, I fail these challenges. However, when I do them manually, including the tests given in the error messages, the calculator seems to work properly. Can anyone take a look at it with me and help me discover if I’m simply missing something, or if there is a bug I should report? I tend to lean towards things being my fault, since I’m the beginner, but I wanted to verify.

Here’s the code

I will admit it’s probably not the prettiest code you’ve ever seen, and could be done more simply.

The function that handles decimals appends a decimal and pushes it to the main array that handles calculations, and then pushes the decimal to a seperate array. If the array contains a decimal, the decimal function won’t allow a decimal to be input. The array is cleared whenever an operator takes place. Hope that simple explanation helps, but I’m happy to try to explain in more detail if that will help you debug! Thanks

@FCCStudent You are definitely not meeting the requirements of test #11 nor does your calculator work properly when entering the following:


Based on the user story, the above should end up displaying 5.55 but your calculator displays 555 after first pressing the AC button which the test does before each new calculation. If you just load the app and repeat the same thing, it does work properly.

Test #13 fails based on what ever caused the decimal points to stop display after the previous test.

Test #14 fails regardless of the other two failing because a user is unable to enter the following sequence:

5 *- 5 =

The above should evaluate to -25 but instead evaluates to 0.

1 Like

Yes, I hadn’t gotten to working through the Multiple operator steps yet - but I see I did not reset the array to empty after pressing all clear. Thanks very much that is definitely why, I was scratching my head for hours trying to figure out why I could get it to work but the script couldn’t!