Combine inputs, functions, branching, and error handling.
- form input
- numeric conversion
- pure calculation
- feedback
A calculator should parse input, validate it, compute with a small function, and display the result. Keep DOM reads and writes separate from the calculation so edge cases are easy to test. State units and rounding rules clearly.
Never rely on a form input's string value being a number.
Build a two-input calculator with addition, subtraction, and multiplication, including invalid-input feedback.
Open example.html in a browser and edit example.js. Save, refresh, and use the Console and debugger to inspect values.
- Explain the core idea in your own words without reading the code.
- Change one input and predict the output before running it.
- Test one boundary or failure case, then record what you changed.