Function Param not working

Tell us what’s happening:
not working…Pls help to resolve

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

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

Your code so far


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

function functionWithArgs ( 7 , 9 ) {
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/86.0.4240.198 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.

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

You call the function with specific values, but

you should not define the function with specific values. That does not make your function reusable, and it just won’t work.

You need to name and use your arguments, like this example

function testFun(param1, param2) {
  console.log(param1, param2);
}
1 Like

Hi @highdreamssathish.

In addition to what @JeremyLT pointed out, function parameters are supposed to be named the way you name variables. You can then pass in arguments when invoking the function. For example you cannot declare a variable like const 1 = 200 because 1 is not a valid variable name or to be exact not a valid identifier.

The same rule applies when declaring functions function foo(1, 2) { return 1 + 2;} is not correct because 1 and 2 are not valid variable names or identifiers. You can do something of the sort:

function foo(arg1, arg2){
    return arg1 + arg2;
}

The above will work because arg1 and arg2 are valid identifiers i.e. They can be used as variable names.
You can read more about identifiers in the answers to this StackOverflow question.

1 Like