Function functionWithArgs confusion

Ok, after seeing the forums, I copied and pasted the code, and it works, but I have no idea why. So far everything has made sense, but I’ve been stuck on this one for a while:

Where do the 3 and 16 come from!?!?

Code:

function functionWithArgs(one, two) {
    console.log(one + two);
}

functionWithArgs (1, 2)

Output

3
3
16
3

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 11_1_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.72 Safari/537.36.

Challenge: Passing Values to Functions with Arguments

Link to the challenge:

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

Pre-formatted-text

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

Hi @liamk

Welcome to FCC forum. Behind the scenes, your code is being tested to determine whether you are submitting the correct solution to answer you question of where 3 and 16 are coming from. Inside the function you are using console.log. Do you know what it does?

Thanks! I know that it passed. I’m just failing to understand it. I don’t understand where the 3 and 16 come from. At no point did I enter an equation, let alone any numbers that would equal to 16. Thanks!

I am not sure I understood you question correctly, but if you look at the bottom left side, the tests are:

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.

The first test just runs your whole “file” and checks if there was an error, printing 3 because you passed (1, 2).
The second test outputs 3 because THEY called it with (1, 2).
The third test outputs 16 because THEY called it with (7, 9).
The fourth test just run you function again.

You need to imagine that somehow (try to ignore the how for now) they are able to swap those numbers to whatever they want. And they just want to find if the sum will be correct.

1 Like

Ahhhh, I see. I wasn’t understanding this at all. Thanks for explaining this for me!

Works, but I cannot explain how this solves anything…

why does this work?

function functionWithArgs(one, two) {
    console.log(one + two);
}
functionWithArgs (1, 2)
-------------------------------------
and not this?

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

Why does using the word "one" or "two" work and not the numbers?

For example:
function functionWithArgs(twenty, two) {
    console.log(twenty + two);
}
functionWithArgs(1, 2)

Works Fine! Is it that a function cannot accept numbers?

you can’t use numbers as variables names
function parameters are variables, so you need to use valid variable names

one, two, twenty are valid variable names, hold the numbers passed in when the function is called so their values are not always 1, 2 and 20, and the function works

1 Like