A simple calculator built with HTML, CSS, and JS.
Try it here: Calculator (published from this repo on GitHub Pages)
- Clickable buttons for numbers and operators
- Prevents multiple decimals in a number
- Allows negative numbers (must enter
-as the first input) - Prevents inputting multiple operators in a row (last entered operator overwrites others)
- Evaluates expressions with correct order of operations
- Automatically resizes font to fit results on the display
- Clear button to reset everything
- Refactored to use classes for better organization and use of OOP principles
- Calculator class creates a calculator that stores numbers and operators in an array as you click on the web interface
- Evaluator class is instantiated when
"="is clicked to evaluate the expression array - Evaluator loops through array searching for operators and executing them according to mathematical order of operations
- The result is displayed on screen, font size adjusts automatically if needed to fit in the results window
index.html: main HTML filemyStyleSheet.css: calculator stylingmain.js: calculator functions and interaction handling
- Clone or download this repository
- Open
index.htmlin your browser - Start clicking buttons to calculate something!
- Keyboard input is not supported
- No parentheses or advanced operations available
- v1.0
- Initial calculator with functional structure
- v1.1
- Converted calculator from functional style to class-based structure
- Fixed display of "Infinity" for division by 0; now displays "Undefined"
