2 Parameters and returns the sum

2 Parameters and returns the sum
0

#1

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?



#2

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”.


#3

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?


#4

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


#5

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

#6

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


#7

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


#8

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


#9

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

#10

Thank you so much! Now it makes sense!


#11
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 );