Passing Values to Functions with Arguments issue

Tell us what’s happening:
Describe your issue in detail here.
Could you help me? What am I doing wrong?

  **Your code so far**

function functionWithArgs(1, 2)
function functionWithArgs(7,9){
console.log(1+2);
console.log(7+9);
}
functionWithArgs("Hello", "World");
  **Your browser information:**

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

Challenge: Passing Values to Functions with Arguments

Link to the challenge:

The parameters that you write when declaring a function work like variables, in a way.

The data placed in the the parenthesis when you call a function is called Arguments

The challenge requires you to do mathematical calculation on the passed arguments.

You’re declaring the function “functionWithArgs” in a wrong way, you also don’t need 2 console.log in the function but only one.

You’ve taken the Arguments that your code will be tested with, and used those as parameters.

I can’t give more hints without telling you the solution, also ever challenge has a hint (inside the Get Help button)

you need to return keyword for add the values… and replace the parameters with characters
for example :-

Mod Edit: SOLUTION REDACTED

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

1 Like

I’m sorry. It’s still not clear for me

In the code that you posted the first thing you did was try and make a function, but you forgot the curly brackets {//enter what you want the function to do here//}. You then properly made a function with two console.logs, but you used actual numbers for the parameters, which i don’t think works. You then called the function with the arguments "Hello" and "World".

here is an example:

//lets make our function
function thisIsTheFunctionName (thisIsAParameter, thisIsTheSecondParameter) {
    //use the parameters in your function to use there values
      console.log(thisIsAParameter + '-' + thisIsTheSecondParameter)
  }
  //lets call our function
  thisIsTheFunctionName('first argument being sent that will be stored in thisIsAParameter', 'the second argument being sent that will be stored in thisIsTheSecondParameter')
  //^^^ function call

So don’t use just numbers as parameter names, and then use those parameters inside the curly brackets {} to add the two values together from the function call (the arguments).

If your still not sure feel free to ask.

1 Like

Sorry for responding late, but which part is confusing you ?

Take a look at the comments I’ve placed in your code.

The first thing your code does, is it gives an error. “Unexpected token” and points to the parameters of the function, to avoid that error letters shall be used as parameters.

A proper way of defining/declaring a function :

function functionName(parameter) {
// code to be executed when function is called 
}
functionName(Argument);  /* function call , it executes any code
 that is in the curly braces where the function is defined. */

The value placed in the argument of the function call, is used at all places where the parameter is mentioned inside the function code.

Also take a look at the above comment for a great example of how Arguments and parameters work.

This is my code now

function functionWithArgs(one, two){

console.log(1+2);

}

functionWithArgs(7, 9)

I still have to pass " functionWithArgs(7,9) should output 16 ."

remember that you have to use the parameters inside your function to use the values passed to them (arguments). in this case the parameters in your new function are one and two, but inside the function you are not adding them together, you are always adding 1+2, which will always be 3.

so when you call the function functionWithArgs(7,9) you are passing the arguments with the value of 7 and 9, but never using them in your function.

Okay, I got you know

function functionWithArgs(one, two){

console.log(one+two);

}

functionWithArgs(7, 9)

Thank you!

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