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:


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) {

You have defined parameters x and y for your function. These are placeholders for values you will pass into the function which will become the values of x and y. The values passed into a function are know as arguments.

For example, let’s say I have the following function:

function subtractNumbers(myValue1, myValue2) {
  return myValue1 - myValue2;

If I want to return the result of 10 - 6, then I would call the above function with:

subtractNumbers(10, 6); // returns 4
1 Like

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