-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathproblme69.js
34 lines (28 loc) · 811 Bytes
/
problme69.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
/*
Implement a simple JavaScript calculator. The calculator should take two numbers and an operator (+, -, *, /) as input and return the result of the operation.
*/
const JsCalculator = (num1, num2, operator) => {
if( operator === '+'){
return num1 + num2 ;
}
else if( operator === '-'){
return num1 - num2;
}
else if( operator === '*'){
return num1 * num2;
}
else if( operator === '/'){
if (num2 === 0) {
return "Error: Division by zero is not allowed.";
}
return num1 / num2 ;
}
else if ( operator === '%'){
return num1 % num2 ;
}
else{
return 'Error: Please inter valid number and mathematical operator.';
}
};
const result = JsCalculator(400, 200, '+');
console.log(result);