Pliz help! Can't seem to pass

Tell us what’s happening:

Your code so far

 // Example
function ourFunctionWithArgs(a, b) {
  console.log(a - b);
ourFunctionWithArgs(10, 5); // Outputs 5

// Only change code below this line.
function functionWithArgs() {
function funtionWithArgs() {
  console.log(7 + 9);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:63.0) Gecko/20100101 Firefox/63.0.

Link to the challenge:

  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.

So first we need to define a function called functionWithArgs, and then call it.

Let’s look at which part of the example is the function definition and break it down.

function ourFunctionWithArgs(a, b) {
  console.log(a - b);

The function keyword tells us that we’re defining a function. Then we give it a name: ourFunctionWithArgs, immediately followed by a bracketed comma-separated list of arguments, or inputs, that can be used in the function body. You can name these arguments whatever you like, in this case they chose to use a and b.

Between the curly brackets is the function body, here we can define what code to run when the function is called. In this example, we get the difference of the arguments a and b via a - b and then log that result to the console with console.log.

Those three lines make up the function definition.

Now that the function is defined, you need to call it to have the code inside the function body run. You can call a function as many times as you want, and with whatever arguments, or inputs, that you’d like. They call the example function with the following code.

ourFunctionWithArgs(10, 5);

The first bit is the name of the function to call, followed by the arguments you want to call it with. In this case, the arguments are 10 and 5. Now the code which was defined earlier will be run, substituting the arguments in the definition with the arguments in the function call, in the same order. So since 10 is the first argument in the caller, it corresponds with a in the definition, and likewise 5 corresponds to b.

The function body in the definition console.log(a - b) will be run as console.log(10 - 5), the result of which is logging 5 to the console.

Now, the great thing about functions is reusability. Maybe I want to try different inputs. Well, we can!

ourFunctionWithArgs(20, 10) // logs 10
ourFunctionWithArgs(10, 10) // logs 0
ourFunctionWithArgs(109238490, 1) // logs 109238489

As you can see, this could be very useful if we need to run the same code multiple times with varying inputs.

So back to the code that you need to write.

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

You need to define a function using the function keyword, and name it functionWithArgs. You need to define two arguments, and then in the function body you need to log the sum of those two arguments to the console. The example function definition does this same thing, except it logs the difference.

  1. Call the function with two numbers as arguments.

Next you need to call the function you defined using two number arguments. In the example, they called their function with the arguments 10 and 5, those are numbers, so you can use the same arguments if you’d like.

  1. You are missing the letter c in the word funCtionWithArgs() .You wrote funtionWithArgs() instead of functionWithArgs()

  2. Your function needs to take the two arguments as inputs. Now your function funtionWithArgs() does not take any arguments as input

  3. Why did you declare the functionWithArgs() function twice?

1 Like