Calculator with History

I recently finished my first main project with javascript with this calculator. I decided to include a saved history of inputs which provided an interesting challenge.

I was wondering what you guys thought about how I organised my javascript code and if you found any bugs.

https://codepen.io/Chalkhous/pen/MNEOmV?editors=0010

1 Like

Hey @Chalkhous, it looks really great, nice work! Unfortunately, almost every case I thought might produce a bug was positive. I think it’s a good example of difference between MVP/prototype and production-level page/app. It’s relatively easy project and most importantly it involves numbers, so I would suggest you to challenge yourself even further and try to polish it to a production-level thing, believe me you will learn A LOT and will be amazed how much more work shall be done here! Knowing how to deal with numbers is a good skill!
Let me know if you’d like to go further with the challenge and I’ll suggest you couple tests you shall complete for your calculator! :wink:

Hey, thanks for the feedback! Could you give a few examples of the bugs you found? I tried my best to get rid of them so I’m not sure on the best way to test it.

I’ll separate test cases to families and will go from most popular to least popular (and I won’t include those that you covered)
1. Edge cases
1A. How do deal with limit of digits on the screen?

  • 99999999999 + 1 should be equal to 100000000000
  • 10000000000 - 0.125 should be equal to 9999999999.875

1B. Do you allow unlimited chain of operations? If yes, how are you going to represent it in history?

  • 1 * 1 * 1 * 1 * 1 * 1 * 1 * 1 * 1 * 4 should be equal 4

2. Misuse
2A. User expect sign % to calculate percentage and not modulo

  • 45% should be equal to 0.45

2B. User must be able to start floating point number with .

  • 45 + .45 should be equal 45.45

2C. User expects CE (Clear entry) to clear entry. Consider sign instead.

3. Numbers and math
3A. Bit truncation (classic)

  • 0.1 + 0.2 should be equal to 0.3

3B. Division by 0 (classic) - any attempt shall be resolved in Error

  • 2 / 0 = + 2 should throw/output an Error

4. Accessibility
4A. User shall be able to use calculator with keyboard input

1 Like

Thanks for taking your time to write all that up! I don’t think I would have thought of any of those cases.
Is 3b necessarily wrong though with 2 / 0 = infinity?

It’s not specifically wrong, as you’re developer and it’s your call at the end. But Infinity + 2 should not equal to 2 - that’s for sure! :wink:

  • Basically Infinity in your case should act as Error and only C/CE should be allowed afterwards.

Ah I see, I misunderstood. That 0.1 + 0.2 case is interesting as well.