SOS -- Passing values to functions with Arguments

I am confused how Im supposed to display at the same time. Ive tried several methods but have failed. Help please.

  **Your code so far**

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

}
functionWithArgs(1, 2);




  **Your browser information:**

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

Challenge: Passing Values to Functions with Arguments

Link to the challenge:

So what would happen if I called your function as follows:

functionWithArgs(5, 6);

What should it print to the console? What does your function print to the console?

functionWithArgs should be a function.

functionWithArgs(1,2) should output 3 .

functionWithArgs(7,9) should output 16 .

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

  1. Create a function called functionWithArgs that accepts two arguments and outputs their sum to the dev console.
  2. Call the function with two numbers as arguments.

This, Ive tried both calling both but Im not formatting it right

Your issue doesn’t have anything to do with formatting. In the body of your function you have

console.log(1+ 2);

This means it will always print 3 to the console no matter what numbers you pass in. You need to fix that.

1 Like

We can read the instructions. But what do you think will happen if the function you have written is called with different arguments?

function functionWithArgs(c, d) {

console.log(1+ 2);

}

functionWithArgs(1, 2);

function functionwithArgs(seven, nine) {

console.log(7 + 9)

}

functionwithArgs(7,9);

this was my initial solution but 7 and 9 isn’t registering

I don’t understand why calling the function twice isn’t permissible

It really, really helps if you interact which the questions we ask…

You have defined (written) the function twice. But you should only define the function once and call it twice.

This function definition has two arguments. You need to use those arguments, c and d, inside of your function so that the behavior of your function changus each time you call your function.

Calling the function twice, or two billion times, is permissible. Defining the function twice is not allowed.

function thisIsMyFunction(this Is An Argument) {
  // this is the function definition
  // you can only do this once
}

// these are function calls
// you can do this many times 
thisIsMyFunction(1);
thisIsMyFunction(42);
1 Like

Okay thanks this gives me an idea of what I did wrong

1 Like