Code
Diff
  • function calculator(num1, num2, operationString) {
      return eval(num1 + operationString + num2)
    }
    calculator(1, 2, "+");
  • 11
    function calculator(num1, num2, operationString) {
    
    2
      if (operationString == "-") {
    
    3
        return num1 - num2;
    
    4
      }
    
    5
      if (operationString == "+") {
    
    6
        return num1 + num2;
    
    7
      }
    
    8
      if (operationString == "*") {
    
    9
        return num1 * num2;
    
    10
      }
    
    11
      if (operationString == "/") {
    
    12
        return num1 / num2;
    
    13
      }
    
    2+
      return eval(num1 + operationString + num2)
    
    1414
    }
    
    1515
    calculator(1, 2, "+");