Build a Calculator - Step 15

Tell us what’s happening:

calculateQuotient function returns “Error: Division by zero” if num2 is zero’
I can not understand it. Please help me!

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 num1 / num2;
}


// 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/140.0.0.0 Safari/537.36

Challenge Information:

Build a Calculator - Step 15
https://www.freecodecamp.org/learn/full-stack-developer/workshop-calculator/step-15

you need to implement this, you need to write the code so that the function returns that message when num2 is 0

This error occurs because, mathematically, dividing a number by zero is an undefined operation and yields no valid result. To understand this better, we can use a simple analogy: dividing pizza. If I divide a pizza into two slices, I get two halves. If I divide it into one slice, I get the whole pizza. But if I divide it by zero… EXACTLY! NOTHING!

In programming, computers treat this type of operation as a fatal error that can cause the program to crash.

For this reason, it is crucial to learn how to handle errors, a topic you will likely cover in more detail later. But for now, here is a simple solution:

code removed by moderator

hi @maxineathos

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.