A web app (on-screen calculator) that performs basic maths operations like add, subtract, multiply and divide.
See the live demo.
- The calculator performs all basic maths like add, subtract, multiply and divide.
- A calculator operation consists of a number, an operator and another number, e.g. 3 + 5.
- The display is populated when the digit buttons are clicked.
- Pressing the
=button evaluates the operation, according to the operator between numbers, and updates the display with the result of the operation. - The calculator does not evaluate more than a single pair of numbers at a time. Example: you enter a number (
12), followed by an operator (+), a second number (7), and a second operator (-). The calculator should first evaluate the initial pair of numbers (12 + 7), then display the result of the calculation (19), and subsequently use this result as the first number in a new calculation, along with the next operator (-). - It rounds answers with long decimals to 2 decimal places.
- Pressing
=before entering all the numbers and operator does nothing (it does not break the calculator): the calculator just waits for you to enter the right input. - Pressing
AC("All Clear") button wipes out any existing data from memory and resets the display to0. - Division by 0 does not crash the calculator: an error message pops up telling you that it is not allowed.
- If you press two operators consecutively, the last operator is used in the calculation. Example: you enter a number (
4), an operator (+), another operator (-), and another number (2). The calculator will evaluate this as4 - 2, giving2as the result. - When a final result is displayed (i.e. the
=button has been clicked), pressing a new digit clears the result and starts a new calculation, but pressing an operator makes the final result the first number in the next operation. - The
+/-button switches the sign of a number; clicking it for the number 0 does nothing. - The
.is used to include a decimal part. Clicking it when the number already has a decimal point does nothing. - There's a "backspace" button to undo your last input if you clicked the wrong number. It works the same way as the
ACbutton if you click it immediately after displaying the final result of an operation (i.e. immediately after pressing the=button).
- Keyboard support
%button and functionality- Another display to capture the full inputs (including the operators), not just the digits.
This project is part of The Odin Project's Full-Stack Web Development Foundations path.
You can reach me on X (Twitter) or LinkedIn.