JavaScriptEasyUtilities

Build a Calculator

Write a calculator function that takes two numbers and an operator (+, -, *, /) and returns the result. Handle division by zero.

Starter code

JavaScript
function calculator(a, b, operator) {
  // Your code here
}

// Test
console.log(calculator(10, 5, '+'));  // 15
console.log(calculator(10, 5, '/'));  // 2

Stuck on this challenge?

Let CodeForge AI help you find the solution.