Apologies if my question is unclear, wasn't sure how to word it!
I'm trying to create a function that takes two numbers and a string which contains an operator (e.g. '+', '-', '*', '/').
I've used .valueOf() on the string to extract the operator, however the num1 and num2 arguments do not seem to evaluate to the passed number parameters. Why is this happening?
function calculate(num1, operator, num2) {
return `num1 ${operator.valueOf()} num2`;
}
undefined
calculate(2, '+', 1);
"num1 + num2" //result