-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasicCalculator.js
More file actions
27 lines (22 loc) · 810 Bytes
/
basicCalculator.js
File metadata and controls
27 lines (22 loc) · 810 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
25
26
27
//Prompts user to enter first and second number.
var firstNumber = prompt("What is the first number?");
var secondNumber = prompt("What is the second number?");
//Establishes mathematical operations and corresponding variables.
var sum = firstNumber + secondNumber
var subtract = firstNumber - secondNumber
var multiply = firstNumber * secondNumber
var divide = firstNumber / secondNumber
var option = prompt("Would you like to add, subtract, multiply, or divide?");
//If loops that correspond with the variables above.
if(option === "add"){
alert("This is your answer: " + sum)
}
if(option === "subtract"){
alert("This is your answer: " + subtract)
}
if(option === "multiply"){
alert("This is your answer: " + multiply)
}
if(option === "divide"){
alert("This is your answer: " + divide)
}