forked from akshitagit/JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculator.js
More file actions
24 lines (21 loc) · 700 Bytes
/
calculator.js
File metadata and controls
24 lines (21 loc) · 700 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// program to create a simple calculator using the if...else...if in JavaScript.
const operator = console.log('Enter operator to perform the calculation ( either +, -, * or / ): ');
const number1 = parseFloat(prompt ('Enter the first number: '));
const number2 = parseFloat(prompt ('Enter the second number: '));
let result;
if (operator == '+') {
result = number1 + number2;
}
else if (operator == '-') {
result = number1 - number2;
}
else if (operator == '*') {
result = number1 * number2;
}
else if (operator == '/') {
result = number1 / number2;
}
else {
window.alert("Please Enter Valid Operator");
}
window.alert(" Result is" + result);