Help with arguments

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

  **Your code so far**

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


functionWithArgs(1,2);

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

ourFunctionWithArgs(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/94.0.4606.81 Safari/537.36

Challenge: Passing Values to Functions with Arguments

Link to the challenge:

Hello there.

Do you have a question?

If so, please edit your post to include it in the Tell us what’s happening section.

Learning to describe problems is an important part of learning how to code.

Also, the more information you give us, the more likely we are to be able to help.


This isn’t the correct function name.

This function doesn’t have any arguments.

(post deleted by author)

Thanks for the advice… Here are the objectives for the challenge:

functionWithArgs should be a function.

functionWithArgs(1,2) should output 3 . (This is the one I am getting wrong)

functionWithArgs(7,9) should output 16 .

You should call functionWithArgs with two numbers after you define it.

I would reset the lesson.

Let’s break down the instructions.
Create a function called functionWithArgs that accepts two arguments

When you create the function here, you need to add two parameters.
You can call those parameters whatever you want to.
Parameters are just placeholders for the real values when you call the function later on.
But the parenthesis cannot be empty here.

If you need help creating parameters, then you can look at the example code again.

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

function testFun(param1, param2) {

Here is the second part of the directions.
and outputs their sum to the dev console.

Inside your function you need to console.log the sum of those two parameters.

Here is the last part of the directions.
Call the function with two numbers as arguments.

You did that part right.

What you need to do is fix is the actual creation of the function.
The correct answer should only be 4 lines of code.

Hope that helps!

here challenge says define function then give parameter and then pass argumets

syntax for that is

  function myfunction(parameter1,paramter2,soON){
                              // your code 
            }
myfunction(argument1,argument2,soON);  // here i call function with arguments

Just copying what the challenge is asking you to do isn’t quite the same thing as telling me what you are confused about. Without additional knowledge I’d just repeat the example that the challenge has. If you tell me what specific part of the instructions or examples don’t make sense though, then I can help explain in more depth.

Thank you, I’ve followed what you said step by step;

the code doesn’t “run” when i place the parameters in the parenthesis, so I negated that yet am still having issues with the sum.

when i use functionWithArg (x2) the code doesn’t run, so I changed one to ourFunctionWithArg and am still running into the “sum” issue.

Thanks for your contribution, if you can could you try your code above for the challenge to see if you have the same issue?

What other code did you write? It’s hard for us to give feedback without seeing your code.

1 Like

Why did you write x2 here?

Maybe you misunderstood what I meant here.

2 Likes

I’m running into issues with the “sums”.

I’ve included parameters in the parenthesis, however the code won’t run.
I’ve kept the same name “functionWithArgs” for both (1,2) and (7,9) but the code only works when i change one of them to “ourFunctionWithArgs”.

Please show us the code you have written with two arguments.

This right here has zero arguments.

Your function definition ( the part that says function myFunction(arg1, arg2) {...}) needs to have two arguments.

1 Like

I agree with @JeremyLT that you should write your new code in the forum so we can see what is going on because there is still some misunderstanding on your end.

When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

2 Likes

This is the new code I tried (doesn’t run):

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

functionWithArgs(1,2);

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

functionWithArgs(7,9);

You should only define your function once (using the function keyword).

When you define the function, your arguments need to be named variables, not numbers, as shown in the example.

Then when you call the function (without the function keyword), then you put numbers in place of those arguments.

1 Like

Ok cool.

I would delete all of this.

Let’s just work with this code here

You can’t pass in real numbers here

or here

You need to create parameter names which act as placeholders for the real values here

Take a close look at the example code I showed you earlier.

Hope that is clearer!

2 Likes

i think you need to understand what parameters are and what argumets are
lets understand with example :

syntax is :

function fun(prameters){
           // yourcode
}
fun(argumets);

cosider i want to multiply two numbers
example :

 function multiply(no1, no2){
         console.log(no1 * no2);
  }
multiply(10,12);

output in console will be 120

now here parameters are those value we are going to use later and arguments are those we are going to pass to our parameters .

1 Like

This is the new code I’ve tried (doesn’t run):

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

functionWithArgs(1,2);


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

functionWithArgs(7,9);

This is possibly so simple yet its still somehow going over my head.

Thanks for your help!

That’s ok.
We are here to help :grinning:

Carefully reread our earlier responses.

Your answer should only be 4 lines of code.
You don’t need to keep creating functionWithArgs again.

It might also help to look at another resource on how to create functions with parameters.

Check out these sources.

1 Like