This project implements a simple calculator using HTML and JavaScript. Users can input two values, choose a mathematical operation from a dropdown menu, and click the "Calculate" button to obtain the result. The code is structured to handle basic arithmetic operations such as addition, subtraction, multiplication, and division.
- Open the
index.html
file in a web browser. - Enter numerical values in the "Enter value 1" and "Enter value 2" input fields.
- Choose a mathematical operation from the dropdown menu.
- Click the "Calculate" button to perform the selected operation.
- The result will be displayed in the "Result" input field.
index.html
: Contains the HTML structure for the calculator interface, input fields, dropdown menu, and result display.script.js
: Implements the JavaScript logic for performing calculations based on user input.
- The
calculate()
function is triggered by clicking the "Calculate" button. - It retrieves the values of the two input fields (
value1
andvalue2
) and the selected operation (math
) from the dropdown menu. - A
switch
statement performs the corresponding arithmetic operation. - The result is displayed in the designated input field (
result
).
- Addition:
+
- Subtraction:
−
- Multiplication:
×
- Division:
÷
- The code assumes valid numerical inputs from the user.
- Division by zero is not handled.
- The result is displayed directly in the input field without formatting or validation.
Feel free to explore and use this simple calculator for basic arithmetic calculations!