Greetings, campers! I’m JesterVae, otherwise known as Johnny V.
I’m mostly finished with my JavaScript Calculator. I’m not proud of the look but I didn’t want to spend too much time primping.
I wanted to do something a little different, and try to create a sort of ‘dummy-proof’ calculator that simply won’t allow you to enter impossible things rather than validating and rejecting.
It was more tedious than I imagined, and there’s still one weird thing I left alone because it does allow the computation: eval() won’t allow you to subtract a negative number (9- -9 is not okay) but it will allow you to add one (9 + - 9 is okay).
Anyway, here’s my calculator.
https://codepen.io/JesterVae/pen/YaMQLd?editors=0011
There are two things I may add in the future:
- A limit to entries to avoid ugliness as it tries to cram the formula into my fixed width.
- Making the current total the first entry of the new formula. As it stands, the formula is maintained until you clear it, but since eval() follows order of operations, the answer may not always be what is expected as the formula gets bigger and more complex.
Feedback is appreciated. Let me know if you find ways to break it. I tried to myself, of course, but I probably missed something. Also, I will comment my code when I’m satisfied with it. Seems like a waste of time when I scrap/rebuild so often as I’m coding.
I initially tried making the enabling/disabling of buttons functions, but it was easier to do the way I did it here. Also, much thanks to Dylan Israel of Coding Tutorials 360 for the basic workings of my calculator.