You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Implement a simple JavaScript calculator. The calculator should take two numbers and an operator (+, -, *, /) as input and return the result of the operation.
*/
constJsCalculator=(num1,num2,operator)=>{
if(operator==='+'){
returnnum1+num2;
}
elseif(operator==='-'){
returnnum1-num2;
}
elseif(operator==='*'){
returnnum1*num2;
}
elseif(operator==='/'){
if(num2===0){
return"Error: Division by zero is not allowed.";
}
returnnum1/num2;
}
elseif(operator==='%'){
returnnum1%num2;
}
else{
return'Error: Please inter valid number and mathematical operator.';