-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
35 lines (26 loc) · 1020 Bytes
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
alert(`Hi, I am Detorlar Mubarak
I'm a Frontend web developer. I built this simple calculator, how about you try it out 😅 yeah?`);
console.log('alert');
//Program for a simple calculator
const operator = prompt("Enter operator (either +,-,* or /):");
const number1 = parseFloat(prompt("Enter first number:"));
const number2 = parseFloat(
prompt(`Enter second number: ${number1} ${operator}`)
);
let result;
if (operator == "+") {
result = number1 + number2;
alert(`Result: ${number1} ${operator} ${number2} = ${result}`);
} else if (operator == "-") {
result = number1 - number2;
alert(`Result: ${number1} ${operator} ${number2} = ${result}`);
} else if (operator == "*") {
result = number1 * number2;
alert(`Result: ${number1} ${operator} ${number2} = ${result}`);
} else if (operator == "/") {
result = number1 / number2;
alert(`Result: ${number1} ${operator} ${number2} = ${result}`);
} else {
alert("Invalid Operator");
}
console.log(`${number1} ${operator} ${number2} = ${result}`);