Skip to content

Latest commit

 

History

History
37 lines (24 loc) · 1.01 KB

README.md

File metadata and controls

37 lines (24 loc) · 1.01 KB

08. Numbers and Math

Handle numeric input, rounding, and special values.

Learn

  • Number()
  • parseFloat
  • NaN
  • Math.round
  • Number.isFinite

How it works

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.

Common mistake

The plus operator joins strings if an operand is text; Number('') becomes zero.

Guided challenge

Read two numeric inputs, calculate a total, and show a clear message for invalid values.

Run the example

Open example.html in a browser and edit example.js. Save, refresh, and use the Console and debugger to inspect values.

Completion check

  • 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.