Just starting learn js, how can I get results like what shows in the examples.
So the require is like this:
Create a function that takes two numbers and a mathematical operator + - / * and will perform a calculation with the given numbers.
Examples
calculator(2, "+", 2) ➞ 4
calculator(2, "*", 2) ➞ 4
calculator(4, "/", 2) ➞ 2
Notes
If the input tries to divide by 0, return: "Can't divide by 0!"
function calculator (a, b) {
let output = 0;
output = a+b;
return output;
}
console.log(calculator(2,2));
Here is what I wrote, only for performing "+".
I thought maybe I should try to add another parameter to repersent "+*/", but I can't get it right.
Anyone can help with it? Thanks