Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

LEVEL 8 LESSON 4(Parameters and Arguments)

We have added code for a function in the editor but the code is incomplete. You have to do the following:

In the function, we want to take two parameters - x and y.

We will store the result of the division of x by y in the result variable. But the division will only be done if the value of the y variable is not equal to 0, because we cannot divide a number by zero, so you will have to provide this condition for the if statement.

The division operation to store the output in the result variable has to be done inside the if block.

At last, call the division function with values x=10 and y=5

function division(x,y)
{
let result;
if(y != 0) {
result = x/y;
console.log("Result:"+ result);
}
else {
console.log("Cannot divide a number by zero");
}
}
// calling the function
division(10,5);

Error :
"Your code's output does not match the expected outcome for this exercise."
by

1 Answer

kshitijrana14
Try this one

function division(x,y)
{
let result;
if(y !== 0) {
result = x/y;
console.log("Result: "+ result);
}
else {
console.log("Cannot divide a number by zero");
}
}
// calling the function
division(10,5);

Login / Signup to Answer the Question.