-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple-calculator.js
More file actions
40 lines (34 loc) · 796 Bytes
/
simple-calculator.js
File metadata and controls
40 lines (34 loc) · 796 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
28
29
30
31
32
33
34
35
36
37
38
39
40
//19-7 Simple calculator to call function inside a function
function add(num1, num2){
const result = num1 + num2;
return result;
}
function subtract(num1, num2){
return num1 - num2;
}
function multiply(num1, num2){
return num1 * num2;
}
function division(num1, num2){
return num1 / num2;
}
function calculator(a, b, operation){
if( operation === 'add'){
const result = add(a, b);
return result;
}
else if(operation === 'subtract'){
return subtract(a, b);
}
else if(operation === 'multiply'){
return multiply(a,b);
}
else if(operation === 'division'){
return division(a,b);
}
else{
console.log("Operation Failed")
}
}
const result = calculator(5, 5, 'division');
console.log(result);