So here’s the calculator I’ve made: (plain HTML5, plain CSS3, plain JS)
I never thought this project would be real hard in the start. After designing the calculator and diving into the JS, the calculations made my head steam. (Not in the sense that I was angry, tho.)
I tried to cover most of the potential bugs that may arise in the project above. If you have comments or suggestions, feel free to drop them in here. And if you have seen any bugs I haven’t known, feel free to reply me here.
Luckily I remembered about the postfix notation and later found the shunting-yard algorithm, to convert any infix notation, e.g. “3 + 5” to its postfix, “3 5 +”. You can check them out if you’re struggling with the calculations, postfix notations make them easier.
There’s also other factors to consider. I found that a lot of potential bugs may arise in this project, without me knowing it. These bugs are actually great lessons.
Example situations that may trigger bugs:
- Clicking operators (+, -, *, /) more than once,
- Clicking an operator first instead of a number,
- Appended more than one decimal point into the display, etc.
That’s all from me. Thank you for reading, guys…