0

function calculator (num1, logicOp, num2) {
  //checking to see if logicOp is an arithmetic value
  switch (logicOp) {
    case "+":
      console.log(num1 + num2);
      break;
    case "-":
      console.log(num1 - num2);
      break;
    case "/":
      console.log(num1 / num2);
      break;
    case "*":
      console.log(num1 * num2);
      break;
  }
  //checking if logicOp is not an arithmetic value
  if (logicOp !== ("*" || "+" || "/" || "-")) {
    console.log("Syntax error");
  } else {
    console.log("Any other calculations?")
  }
}

calculator(75, "/", 5);

Im trying to create a basic calculator that can perform arithmetic between two numbers, I am having problems checking if what they have put in as an arithmetic operator is actually arithmetic, I have tried using the or operator in multiple ways in an if statement but nothing worked.

0 Answers0