Home/Projects/Calculator
Shipped
Web Development

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.

recruiter perspective

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
Try it live
Hiring Summary

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.

Challenges Addressed
  • Operator chaining: pressing + after = should chain from the result
  • Floating-point display: avoid showing 0.30000000000000004
  • Keyboard support for digits, operators, Enter, Backspace, Escape
◆CalculatorWEB DEVELOPMENT/visual-placeholder

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.

Stack
JavaScriptHTMLCSS
Decision
Explicit state machine over display-driven logic
Many calculator bugs come from reading state from the display string. An explicit state machine with typed fields makes transitions predictable and testable.
Tradeoff
Floating-point precision vs. simplicity
Chose: parseFloat(result.toPrecision(10))
Rounding to 10 significant digits before display eliminates visible floating-point noise without meaningful precision loss for a basic calculator.
01Scientific calculator mode with trig functions
02Expression history with replay
03Parentheses support with full expression parsing