A calculator app using vanilla JavaScript, HTML, and CSS
The calculator contains functions for all of the basic math operators typically found on basic calculators.
- (1) Created functions for the following items: addition, subtraction, multiplication, and division.
- (2) Created a function that takes an operator and 2 numbers and then calls one of the above functions on the numbers.
- (3) Created a basic HTML calculator with buttons for each digit, each of the above functions, an “equals” key, a "clear" key, and a display.
- (4) Created functions that populate the display when a user clicks the number buttons. The display value is stored in a variable for use in the next step.
- (5) Stored the first number input into the calculator when a user presses an operator, saved the operation selected, called the operate() function on the values (input and operator) when the user presses the “equals” key, and then updated the display with the solution to the operation.
- (6) Created the logic that stores all of the values and calls the operate() function - the calculator evaluates a single pair of numbers one at a time.
- (7) Created error message when user attempts to perform invalid operations (e.g., dividing by 0).
- (8) Created function that clears the operation once the solution is displayed.
- (9) Added a "period" key in order to use decimals for one single place value.
- (10) Added a "backspace" button in order for users to edit any errors.