Cant figure out what the problem is

Tell us what’s happening:
`` I have been following the instructions and examples but I still get an error code saying
functionWithArgs(7,9) should output [16] ```

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(a, b) {
console.log(1 + 2) + (7 + 9);
}

functionWithArgs(3, 16);



Your browser information:

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

Challenge: Passing Values to Functions with Arguments

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

As I can see, your call to console.log isn’t correct. You’re dealing with primitive values (1 + 2) while you should be dealing with the arguments a and b in order to get the correct result.

// Only change code below this line.
function functionWithArgs(a, b) {
console.log(1 + 2) + (7 + 9);  //Double check this line
}

thanks for responding so quickly! I guess what i am asking is, why am I only able to get the correct output for the first parameter (1 + 2 = 3) but not for the second (7 + 9 = 16)? How do I refer to both arguments, not just one?

actually, i just figured it out by fluke, still dont really understand how that worked.

function functionWithArgs(a, b) {
console.log(a + b);
}

functionWithArgs(3, 16);

which is apparently correct, but it says the outputs are 5, 3, and 19… not 16… so I am confused at where 19 came from.

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

// Only change code below this line.
function functionWithArgs(a, b) {
    
       console.log(1 + 2) + (7 + 9);
       // this is what's happening here: 3 + 16 = 19
      // you need to pass in the arguments! (hint)
}

functionWithArgs(3, 16);


/ Only change code below this line.
function functionWithArgs(a, b) {
    
       console.log(a + b);
       // pass 7 into a, and 9 into b!  
}

console.log(functionWithArgs(7, 9));    // 16

That 19 basically came as a result from the definition of your function that says:

console.log(a + b);

In other words: sum the values of a and b passed as arguments to the function and print it out.
So when you call your function like this:

functionWithArgs(7, 9);

You’re telling your function to sum the values of a and b which are respectively 7 and 9.

This has definitely helped to clear some things up, thank you so much. I am trying it your way to see how it all works

1 Like