Build a Calculator - Step 15

Tell us what’s happening:

Just running into an issue of how exactly the instructions want this to be returned to prevent the edge case of dividing by 0.

could use some assistance/pointeqVjoNO leave feedback
r

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

// User Editable Region


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

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36

Challenge Information:

Build a Calculator - Step 15

… check if num2 is zero. If it is, the function should return the string "Error: Division by zero" . Otherwise, it should return the result of dividing num1 by num2 .

Were you asked to log anything in this step?

No I wasn’t asked to log anything oddly enough I was sure that is what it was asking me, I may try an additional console.log outside the block to error check. However I’m doing something wrong and am unsure what.

I replaced the console.log line with : return “Error: Division by zero”; and still no avail.

Hmmm… that should have worked. Please post your updated code.

Here is the updated code for this question:

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

yeah I feel it should have worked too, yet I feel something entirely small is impeding my progress as a simple extra space has completely broken my entire code before on here before.

Did you close your function block? :slight_smile:

2 Likes

ah I see, I’ll see to it that is fixed and let you know the results.

Thanks a ton for your time, haha every error I have I’m always like “How could I have missed that.“, seems that is always the case. :sweat_smile: