Basic JavaScript - Passing Values to Functions with Arguments

Tell us what’s happening:
Not sure what is wrong

Your code so far

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

Your browser information:

User Agent is: Mozilla/5.0 (Linux; Android 11; TECNO KG5k) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Mobile Safari/537.36

Challenge: Basic JavaScript - Passing Values to Functions with Arguments

Link to the challenge:

And, this is the challenge:

  1. Create a function called functionWithArgs that accepts two arguments and outputs their sum to the dev console.
  2. Call the function with two numbers as arguments.

The following code is calling a function with two arguments, the values 3 and 16 - that is the second point in the challenge.

functionWithArgs(3, 16);


Discussion about point 1 :

An example function without arguments:

function functionWithoutArgs() {
    console.log("Hello!");
    console.log("1 + 3 = ", 4);
}

When you run this function:

functionWithoutArgs();

It prints on the console:

Hello!
1 + 3 = 4

Here is an example function with one argument:

function exampleFunction(name)  {
    console.log("Hello", name);
}

Run this function:

exampleFunction("World");

The output on the console is, Hello World

Thats how arguments are defined in a function and are used in it.

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

You should pass argument on top between parenthesis
and inside the function you should show output by using the value you passed at the top
for e.g.

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

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.