Build a Calculator - Step 15

Challenge Information:

Build a Calculator - Step 15

Tried a couple different variations of this but as far as I can tell this should work or am I missing something?

function calculateQuotient(num1, num2) {
  if (num2 === 0) {
    return console.log("Error: Division by zero");
  }
  else {
    return num1 / num2;
  }
}

Your code so far

function calculateSum(num1, num2) {
  return num1 + num2;
}

console.log(calculateSum(2, 5));
console.log(calculateSum(10, 10));
console.log(calculateSum(5, 5));

function calculateDifference(num1, num2) {
  return num1 - num2;
}

console.log(calculateDifference(22, 5));
console.log(calculateDifference(12, 1));
console.log(calculateDifference(17, 9));

function calculateProduct(num1, num2) {
  return num1 * num2;
}

console.log(calculateProduct(13, 5));


// User Editable Region


function calculateQuotient(num1, num2,) {
  return num2 <= 0 ? console.log("Error: Division by zero") : num1 / num2;
}


console.log(calculateQuotient(3, 0));

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36

1 Like

console.log doesn’t return a string

1 Like

Ahh, thanks bud!

function calculateQuotient(num1, num2, error) {
  if (num2 === 0) {
    error = "Error: Division by zero"
    return error;
  }
  else {
    return num1 / num2;
  }
}

My solution with ternary operator:

code removed by moderator

hi @piunoff

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge. How to Help Someone with Their Code Using the Socratic Method

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.