Passing Values to Functions with Arguments-solved

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(1,2) {
  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/71.0.3578.98 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/passing-values-to-functions-with-arguments

You’re missing the point of functions. A function is used to package up a small bit of reusable functionality: it takes some input and uses that input to generate some output. So look at the example. This is how the function is defined:

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

It uses a and b

Then you use the function by putting values in:

ourFunctionWithArgs(10, 5)

a is 10 and b is 5. But it could just as well be 100000 and 2. Or 4.35 and 0.927. Or -27 and 67.

You don’t define the function like this:

function ourFunctionWithArgs(10, 5) {
  console.log(10 - 5);
}

There’s no point. Even if it worked, you could just write console.log(5) instead and it would be exactly the same, there would be no point in writing the function.

hey @DanCouper thank you for your advise.

regards

1 Like