A lightweight, vanilla‑JavaScript calculator that runs entirely in the browser. SimpleCalc provides the essential arithmetic operations with an intuitive button layout, keyboard shortcuts, and graceful error handling – all without any build steps or external dependencies.
- HTML5 – Semantic markup for the calculator UI.
- CSS3 – Flexbox layout, responsive design, and visual styling.
- JavaScript (ES2021) – Core logic for expression evaluation, event handling, and keyboard support.
- Basic arithmetic: addition, subtraction, multiplication, division.
- Decimal numbers and chaining of operations.
- Clear (C) and backspace (⌫) functionality.
- Percentage (
%) handling (interpreted as/100). - Sign toggle (±) for the current number.
- Keyboard shortcuts for all buttons (e.g.,
1‑9,0,+,-,*,/,Enterfor=). - Real‑time display of the current expression and result.
- Graceful handling of division by zero and malformed expressions with user‑friendly error messages.
- Responsive layout that works on desktop and mobile browsers.
- Clone the repository
git clone <repository-url> cd SimpleCalculator
- Open the app
- Double‑click
index.htmlor open it in any modern browser (Chrome, Firefox, Edge, Safari, etc.). - No build step, server, or package manager is required – the app is pure client‑side.
- Double‑click
┌─────┬─────┬─────┬─────┐
│ C │ ⌫ │ % │ ÷ │
├─────┼─────┼─────┼─────┤
│ 7 │ 8 │ 9 │ × │
├─────┼─────┼─────┼─────┤
│ 4 │ 5 │ 6 │ - │
├─────┼─────┼─────┼─────┤
│ 1 │ 2 │ 3 │ + │
├─────┼─────┼─────┼─────┤
│ ± │ 0 │ . │ = │
└─────┴─────┴─────┴─────┘
- C – Clear the entire expression.
- ⌫ – Delete the last character (backspace).
- % – Percentage (interpreted as
/100). - ÷, ×, -, + – Arithmetic operators.
- ± – Toggle sign of the current number.
- . – Decimal point.
- = – Evaluate the expression.
| Key | Action |
|---|---|
0‑9 |
Enter corresponding digit |
. |
Decimal point |
+, -, *, / |
Operators (* = multiplication, / = division) |
Enter or = |
Evaluate (=) |
Backspace |
Delete last character |
Escape |
Clear all (C) |
Shift + % |
Percentage |
Ctrl + ± |
Toggle sign |
Error: Division by zero– Shown when the expression attempts to divide by zero.Error: Invalid expression– Shown for malformed input (e.g., two operators in a row).- Errors replace the result display until the user clears or edits the expression.
The calculator uses a flexible Flexbox grid and media queries to adapt to different screen sizes. On mobile devices the buttons and display scale down while remaining easily tappable, ensuring a smooth experience on both portrait and landscape orientations.
| File | Purpose |
|---|---|
index.html |
Markup – layout of the calculator UI and display area. |
styles.css |
Styling – Flexbox grid, responsive adjustments, and visual theme. |
script.js |
Core JavaScript – expression parsing, evaluation, event handling, and keyboard support. |
README.md |
Project documentation (this file). |
LICENSE |
MIT license placeholder. |
Contributions are welcome! Feel free to open issues or submit pull requests.
- Fork the repository.
- Create a feature branch (
git checkout -b feature/awesome‑feature). - Make your changes, ensuring the calculator still works by opening
index.html. - Commit with a clear message and push to your fork.
- Open a pull request against the
mainbranch.
Please keep the code style consistent (ES2021, 2‑space indentation) and avoid adding external dependencies.
This project is licensed under the MIT License – see the LICENSE file for details.