2 Parameters and returns the sum

I’m trying to work on this exercise but I’m stuck kind of, what am I doing wrong? Or i didn’t get the question?


When you are calling your function you aren’t passing in any parameters. x and y are both undefined. You can’t add them together because they’re not numbers. NaN is “Not a Number”.

while I was trying to put numbers in the paramethers it was giving me a erorr,
“function addNumbers(x(2), y(2))” would this be something to work on?

x(2) and y(2) aren’t numbers either.

This is where you are defining a function:

function addNumbers(x, y) {
  return x + y;
}

This is where you are trying to execute that function. What you are trying to execute does not match the definition:

addNumbers()

I don’t get it, what am I doing wrong? in this case the output should be xy isn’t it?

When you call the function you have to set the parameters:
addNumbers(2 + 2);

it gives me error when I do this;
function addNumbers(2 + 2) {
}

Thank you so much! Now it makes sense!

function addNumbers( x + y ) {
return x + y
};

Here you are creating a function in which you have 2 parameters, return x + y is returning the sum of these parameters. When you call the function you have to define said parameters, e.g.:
addNumbers( 2 + 2 );

1 Like