Basic JavaScript - Passing Values to Functions with Arguments

OK, so once again I am back with a “I passed” but don’t understand question. So, I am somewhat in the loop and understand how I got the the solution sort of…

However, when I console logged it for an output at first it didn’t pass but it told me the values needed to be 3 and 16. So I just changed the values of a and b to work to equal what the output told me it should equal.

I don’t understand where these values came from and why it wanted me to get 3 and 16.

From the directions I am very confused, can someone run through this with me.

Thank you!

Tell us what’s happening:
Describe your issue in detail here.

Your code so far

function functionWithArgs(a, b){
  console.log(a + b)
}
functionWithArgs(1, 2)

function functionWithArga(a, b){
  console.log(a + b)
}
functionWithArgs(7, 9)

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36

Challenge: Basic JavaScript - Passing Values to Functions with Arguments

Link to the challenge:

The second part of the instructions asks you to call your function with two numbers, for example:

functionWithArgs(1, 2)

Your function then adds those two numbers together and prints the sum to the console. So for the example above it will print 3 to the console.

Does that answer your question? If not then you might need to be a little more specific about what your question is.

P.S. The second function you defined is not needed. You should only create one function with the name functionWithArgs. Your second function has a different name.

1 Like

I think the lesson just wants to make sure you know how calling a function works. It wants you to figure out which two numbers are needed in the argument part of the function to get the answer of 3 and 16, Which requires you to call the function twice to get each number. I hope this helps and makes sense.

Also I noticed that you wrote the function twice. That is not needed. You only need to create the function once and it can be called at anytime and multiple times.

I don’t think there is any requirement on the numbers you can use to pass this challenge. I just did

functionWithArgs(10, 11);

And it passed just fine. The tests are passing in their own numbers which do add up to 3 and 16. But you don’t need to worry about that. But if your function doesn’t do what it is supposed to do then those internal tests won’t pass and you will get the following errors in the console:

functionWithArgs(1,2) should output 3.
functionWithArgs(7,9) should output 16.

This is just telling you that the tests tried to run your function with those numbers and your function didn’t produce the correct results.

So its just a suggestion to steer you to the right path?

I thought those values were needed to pass and thought I may be missing something via the directions.

i’ll go back an try different values.

Thank you.

No. It’s just showing you the values that the internal tests are using to test your function. Those tests could use any values they wanted. The error messages you were seeing is saying “If I pass 1 and 2 into your function then I should see the value 3”. The tests could have used 100 and 1000 instead. Those are just two arbitrary numbers that the person who created the tests chose to use. The fact that you were seeing those messages meant that your function wasn’t correct. It didn’t have anything to do with the numbers you were passing into your function.

Hi Snacks201!

I will try to explain a little here and I hope it can help you understand the concept of parameters and arguments in a function.

Parameters are placeholder/identifier inside a function. In this context, when you first declare functionWithArgs(a, b) —> (a,b) are acting as parameters. At this moment, the parameters still don’t have any value. To make it easier, think of declaring a variable like this:
let a;
let b;

However, when you invoke the function with functionWithArgs(7, 9) —> the parameters now have the following value:
a= 7;
b=9;

Therefore, the console.log(a+b) is now console.log(7+9)

Hope this helps.

UGHHH ok, so wow. I didn’t realize that this was here…

When my browser goes to the next test and displays the screen, I was unaware that if I scrolled down that there was more displayed. :expressionless:

So yeah I was just confused because I read the diretions multiple times and now I realize those are where the values the test wants you to use comes from.

Thanks for all the help

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.