📅  最后修改于: 2022-03-11 15:04:27.583000             🧑  作者: Mango
function calculate(number1,number2,operator){
if (!number1 || !number2){
return "Invalid number"
}
if (!['*','-','/','+'].includes(operator)){
return "Invalid operator"
}
switch(operator){
case "+":
return number1 + number2;
case "/":
return number1 * number2;
case "*":
return number1 * number2;
case "-":
return number1 - number2;
}
}
console.log(calculate(5,6,"+"))