/js-calculator

A calculator using React and logical rules to determine appropriate user input

Primary LanguageCSSMIT LicenseMIT

JS Calculator

Fully functional calculator built in React. Enforces logical rules around user input, such as:

  • Expression must start with a number, ., or negative sign
  • Expression cannot contain two operators in a row (with the exception of a minus sign)
  • A number can only contain a single decimal point
  • Pressing a number immediately following = should start a new calculation
  • Pressing an operator immediately following = should start a new calculation that operates on the result of the previous evaluation
  • Handles > 5 decimal places of precision with rounding, indicated by ~ symbol

Demo

calculator