Ad
Code
Diff
  • function calculator(num1, num2, operationString) {
      return eval(num1 + operationString + num2)
    }
    calculator(1, 2, "+");
    • function calculator(num1, num2, operationString) {
    • if (operationString == "-") {
    • return num1 - num2;
    • }
    • if (operationString == "+") {
    • return num1 + num2;
    • }
    • if (operationString == "*") {
    • return num1 * num2;
    • }
    • if (operationString == "/") {
    • return num1 / num2;
    • }
    • return eval(num1 + operationString + num2)
    • }
    • calculator(1, 2, "+");