forked from formkergit/foad-javascript-base
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript-3.js
More file actions
32 lines (29 loc) · 790 Bytes
/
Copy pathscript-3.js
File metadata and controls
32 lines (29 loc) · 790 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
/*
* calculatrice
* -------------------------------------------------
* inputs :
* operand1 : First operand as a number
* operand2 : Second operand as a number
* operator : operator as a string
* Allowed operators are + - * /
* output :
* Result of the operation
*/
function calculatrice(operand1, operand2, operator) {
switch (operator) {
case "+":
return operand1 + operand2;
case "-":
return operand1 - operand2;
case "*":
return operand1 * operand2;
case "/":
return operand1 / operand2;
default:
return undefined;
}
}
let op1 = 5;
let op2 = 10;
let operator = "+";
console.log(`${op1} ${operator} ${op2} =`, calculatrice(op1, op2, operator));