Can't figure it out! Functions w/Arguments

Tell us what’s happening:
So i’ve been 3 days without figuring out, tried to learn everywher and still says i need to make functionWithArgs(1,2) output 3. Tried everything i could remember.

Your code so far


function functionWithArgs(three, sixteen) {
console.log(1 + 2);
console.log(7 + 9);
}

functionWithArgs(3,16);

it will console.log 3 and 16.

Challenge: Passing Values to Functions with Arguments

Link to the challenge:

You need to return the value with the “return” statement

I think return is the next lesson.

The issue is that you are logging out hardcoded addition. You should use the parameters that are being passed. And the parameters should have more generic names.

1 Like

In the above, you’ve defined two parameters. They are simply variables that can only be seen inside the function. What are those variables? You’ve named them three and sixteen.

Now those names are confusing, because they might have a value of true or 42 or "blue". But you have two variables. How might you add them?

The parameters of a function are like boxes you can put a value in so you can use it inside the function. You have to give that box a name, just like a variable. The name isn’t necessarily the contents, but usually has to suggest whats in the box.

function printMyPetsName (petsName) {
   console.log (petsName);
}

So that function can be given a pets name, and it will take that pets name, and print it to the console. To use a function you have to call it (which is not part of this challenge). Therefore, if I have that function above, and I want to use it, it would look like this:

printMyPetsName ("Festus");

That code should print “Festus” to the console using the function we wrote. I hope that makes sense and helps.