-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimpleCalculator.js
More file actions
27 lines (23 loc) · 1.06 KB
/
Copy pathsimpleCalculator.js
File metadata and controls
27 lines (23 loc) · 1.06 KB
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
/* You are required to create a simple calculator that returns the result of addition, subtraction, multiplication or division of two numbers.
Your function will accept three arguments:
The first and second argument should be numbers.
The third argument should represent a sign indicating the operation to perform on these two numbers.
if the variables are not numbers or the sign does not belong to the list above a message "unknown value" must be returned.
Example:
calculator(1,2,"+"); //=> result will be 3
calculator(1,2,"&"); //=> result will be "unknown value"
calculator(1,"k","*"); //=> result will be "unknown value"
Good luck! */
function calculator(a,b,sign){
if(sign === '+' && Number.isInteger(a) && Number.isInteger(b)){
return a + b
}if(sign == '-' && Number.isInteger(a) && Number.isInteger(b)){
return a - b
}if(sign == '*' && Number.isInteger(a) && Number.isInteger(b)){
return a * b
}if(sign == '/' && Number.isInteger(a) && Number.isInteger(b)){
return a / b
}else {
return 'unknown value'
}
}