freeCodeCamp Challenge Guide: Passing Values to Functions with Arguments

Passing Values to Functions with Arguments


Problem Explanation

Our task is to create a function that has parameters. These are inputs that determine the function’s output. You place paramaters inside the (), like so:

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

We now have to add code inside the brackets. Our task is to add one and two, and print the sum to the console.

functionWithArgs(7, 3);
//This will console log 10.
12 Likes

I have same code as you but I get this as failure messages:

functionWithArgs(1,2) should output 3
functionWithArgs(7,9) should output 16

4 Likes

In the end it was missing a ‘+’ sign in the console.log instead of a ,

// Only change code below this line.
function functionWithArgs(param1, param2) {
console.log(param1 + param2);
}
functionWithArgs(“Hello”, " World");

3 Likes

guys can anyone tell me that where’s the problem in this.
// 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(a + b);
}
FunctionWithArgs(50, 13);

1 Like

function functionWithArgs(a,b) {
console.log(a+b);
}
functionWithArgs(1,2); \= 3
functionWithArgs(7,9); \= 16
DONE

23 Likes