javascript
Published on January 26, 2024By DeveloperBreeze
// Function to perform basic arithmetic operations
function calculate(a, b, operator) {
switch (operator) {
case '+':
return a + b;
case '-':
return a - b;
case '*':
return a * b;
case '/':
return a / b;
default:
return 'Invalid operator';
}
}
// Example: Perform addition (10 + 5)
const result = calculate(10, 5, '+');
console.log('Calculator Result:', result);
Comments
Please log in to leave a comment.