Basic JavaScript - Passing Values to Functions with Arguments

Tell us what’s happening:

Hi please help me with the below , im get the (7,9) but not the 1st one

What am i doing wrong

Your code so far

function functionWithArgs(a, b) {
console.log (1 + 2);
console.log (7 + 9);

}
functionWithArgs(1,2);
functionWithArgs(7,9);

Your browser information:

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

Challenge Information:

Basic JavaScript - Passing Values to Functions with Arguments

your function will always print to the console the same two numbers, 3 and 16, but the point of using arguments is to make it reusable, so that any number could be passed to the function and be used in the sum. You are not using the arguments of the function, a and b, but hardcoding numbers. So if I would call the function as functionWithArgs(1, 1) this would print again 3 and 16, not the 2 I would expect.

2 Likes

Think of the function as a television. A television does not contain all the movies and TV shows ever made. It can be sent “values” to be displayed.

Your function should be able to add together any two numbers that are sent to it. It doesn’t matter what numbers you need to add together, the numbers are sent, and the function will add them together and give you back the result.

2 Likes