Basic JavaScript - Passing Values to Functions with Arguments

I think I’m doing the right thing but i still won’t pass the challenge, I’m stucked & I need help please…

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

function functionWithArgs(7, 9) {
console.log(7 + 9);
}

functionWithArgs(7, 9);
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36

Challenge: Basic JavaScript - Passing Values to Functions with Arguments

Link to the challenge:

I went ahead and removed that hard profanity for you since we try to keep the forum family friendly for our younger users.

You should only declare the function once, using the ‘function’ keyword.

Also, you must use variables in the function definition and not specific numbers. You only use specific numbers for the function call.

But the challenge wants me to only use numbers, I’m not sure if you went through the challenge, instruction…

Maybe you missed this part of the instructions.

Create a function called functionWithArgs that accepts two arguments and outputs their sum to the dev console.

Call the function with two numbers as arguments.

I’m kinda confused right now this is one of the reasons why i hate Fcc they don’t explain in details in their example

FreeCodeCamp doesn’t give you examples to copy-paste without understanding, but the explaination here is pretty good:

Parameters are variables that act as placeholders for the values that are to be input to a function when it is called. When a function is defined, it is typically defined along with one or more parameters. The actual values that are input (or “passed”) into a function when it is called are known as arguments.

Here is a function with two parameters, param1 and param2:

function testFun(param1, param2) {
  console.log(param1, param2);
}

In the language presented here, the challenge is asking you to make a function with two parameters.

Then we can call testFun like this: testFun("Hello", "World");. We have passed two string arguments, "Hello" and "World".

In the language presented here, the challenge is asking you to call the function twice, each time with different arguments.

This exactly what I’ve done…I created a function called functionWithArgs and inputed two numbers into my function and we can’t only specify numbers that could be anything…

Nope. It is not what you have done.

As I said, you have two problems with your code

  1. You declared your function twice but you must only use the function keyword once and must only declare your function a single time

  2. You cannot use numbers as your parameters in the function declaration. You must use variables that represent the numbers.

Here is an example of a function call with two strings.

But here in the function definition:

the parameters are variables.

Here’s my code below again…

function functionWithArgs(Code, Hechter) {
console.log(1 + 2);
}
functionWithArgs(1, 2);

function functionWithArgs(7, 9) {
  console.log(7, + 9);
}

You changed it, but its still wrong in the two ways I explained.

Here is your first function declaration

And the second:

You must have only one function declaration.


Here you created the parameters Code and Hechter, which is good, but you never used them inside of your function.

I changed the parameters to variables & still won’t pass the challenge…i’m kinda gettting frustrated!!!

You need to fix all of the problems with your code, not just some of them.

Coding can be frustrating. You need to do exactly what the task says because the computer cannot ‘guess’ what you mean. It only understands the literal syntax you type.

How do i declare just one function when the challenges wants me to have 2 outputs which are “3” and “16” respectively??

You only declare the function once, but the tests call it twice.

From the instructions:

Note that you could call testFun again with different arguments and the parameters would take on the value of the new arguments.

So when the instructions say

Create a function called functionWithArgs that accepts two arguments and outputs their sum to the dev console.

That is telling you to declare the function once.

And here

Call the function with two numbers as arguments.

The instructions are telling you to call the function once. You could call it multiple times if you want.

The values passed in as function arguments are what make the function do something different on each function call. That is the purpose of the function arguments, and it is the entire reason for writing a function.

Each time you call a function, you are telling the code to execute the steps inside of the function with the specific values you passed in as arguments in place of the parameters that are part of the function definition.

1 Like

I’ll just leave it for another day I’m frustrated right now

You said the instruction wants me to call the function once & you also said again i could call the function multiple times…You are confusing me i must say!!!

If you have called the function twice, then you called it once as well. I’m pretty sure 1 + 1 = 2, so you need to call it one time as part of calling it twice :upside_down_face:

The tests will call your function multiple times to make sure it works correctly.

This sucks so much :sob: :sob: :sob: :sob:

Does it mean I’ve declared the function once here??

function functionWithArgs("Code1", "Hechter2") {
  console.log(1 + 2);
}
functionWithArgs(1, 2);