Ad
Code
Diff
  • let operations = {
      "+"(n1, n2) {
        return n1+n2;
      },
      "-"(n1, n2) {
        return n1-n2;
      },
      "*"(n1, n2) {
        return n1*n2;
      },
      "/"(n1, n2) {
        return n1/n2
      }
    }
    function calculator(num1, num2, operationString) {
      return operations[operationString](num1,num2)
    }
    calculator(1, 2, "+");
    • let operations = {
    • "+"(n1, n2) {
    • return n1+n2;
    • },
    • "-"(n1, n2) {
    • return n1-n2;
    • },
    • "*"(n1, n2) {
    • return n1*n2;
    • },
    • "/"(n1, n2) {
    • return n1/n2
    • }
    • }
    • function calculator(num1, num2, operationString) {
    • return eval(num1 + operationString + num2)
    • return operations[operationString](num1,num2)
    • }
    • calculator(1, 2, "+");