Calculator
A calculator implementation built to practice event handling, floating-point arithmetic edge cases, and display state management — specifically the subtle bugs in operator chaining and decimal rounding that naive implementations get wrong.
Calculator with keyboard support and explicit state machine for edge case handling
- ›Explicit state machine handles operator chaining and consecutive operations correctly
- ›Floating-point display rounding eliminates floating-point noise
- ›Full keyboard support for digits, operators, Enter, Backspace, Escape
A browser calculator with keyboard support, operator chaining, and floating-point display rounding. Implemented with an explicit state machine to handle the edge cases naive display-driven approaches get wrong.
Implement a calculator that handles operator chaining, floating-point display, and keyboard input correctly — the classic web development fundamentals project that reveals more edge cases than expected.
- Operator chaining: pressing + after = should chain from the result
- Floating-point display: avoid showing 0.30000000000000004
- Keyboard support for digits, operators, Enter, Backspace, Escape
Vanilla JavaScript with explicit state machine: accumulator, operand, operator, and displayValue. Each button/key dispatches an action that transitions the state machine and updates the display.