-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask46.js
30 lines (26 loc) · 855 Bytes
/
task46.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
//Basic Mathematical Operations
/*Your task is to create a function that does four basic mathematical operations.
The function should take three arguments - operation(string/char), value1(number), value2(number).
The function should return result of numbers after applying the chosen operation.
Examples(Operator, value1, value2) --> output
('+', 4, 7) --> 11
('-', 15, 18) --> -3
('*', 5, 5) --> 25
('/', 49, 7) --> 7
*/
function basicOp(operation, value1, value2) {
switch (operation) {
case "+":
return value1 + value2;
case "-":
return value1 - value2;
case "*":
return value1 * value2;
case "/":
return value1 / value2;
}
}
Test.assertSimilar(basicOp("+", 4, 7), 11);
Test.assertSimilar(basicOp("-", 15, 18), -3);
Test.assertSimilar(basicOp("*", 5, 5), 25);
Test.assertSimilar(basicOp("/", 49, 7), 7);