Build a Calculator - Step 15

Tell us what’s happening:

I already tried this function in codepen.io, and it works just fine; however, here, it doesn’t work at all! ugh! Gives me the error message: 2. Your calculateQuotient function should return the result of dividing num1 by num2 if num2 is not zero. So I switched the order and it still doesn’t work!

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) {
  if (num1/num2) {
  }
    else if (num2 === 0);
  return "Error: Division by zero";

}



// User Editable Region


console.log(calculateQuotient(7, 11));
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/136.0.0.0 Safari/537.36 Edg/136.0.0.0

Challenge Information:

Build a Calculator - Step 15

Hi @BooBoo212

  1. Your calculateQuotient function should return the result of dividing num1 by num2 if num2 is not zero.

You need to check what the condition is checking, and what the function returns.

Check the last message in the console.

Happy coding

1 Like

if (num2 === 0) {
return “Error: Division by zero”;
}
return num1 / num2;
}
console.log(calculateQuotient(7, 11));
console.log(calculateQuotient (3, 0));

tried this, too! function calculateQuotient(num1, num2) {
return num2 === 0 ? “Error: Division by Zero” : num1/num2;
}

Hi @BooBoo212

Your ternary goods great. You have a casing issue.

Your calculateQuotient function should return the string "Error: Division by zero" if num2 is zero.

Happy coding