Handle numeric input, rounding, and special values.
- Number()
- parseFloat
- NaN
- Math.round
- Number.isFinite
Browser input values arrive as strings. Convert explicitly before arithmetic and test for finite results. Floating-point values can have small representation errors, so define a rounding policy for display and avoid treating rounded display values as exact accounting data.
The plus operator joins strings if an operand is text; Number('') becomes zero.
Read two numeric inputs, calculate a total, and show a clear message for invalid values.
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.