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.
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