Function values as arguments

The goal is to log the sum of two numbers passed into the function, and print them into the console. For some reason, the second pair of numbers (7,9) into the function, will not add up or print to the console.

When I add (1+2) in the console.log, it works fine. But when I tried adding (7+9), it wouldn’t run

What am I doing wrong?

Your code so far


// Example
function ourFunctionWithArgs(a, b) {
  console.log(a - b);
}
ourFunctionWithArgs(10, 5); // Outputs 5

// Only change code below this line.

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

functionWithArgs(7,9);

Your browser information:

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

What do you think functionWithArgs(7,9) should display as a value?

I’ll change the name of the first function, it might make it clearer:

function subtract(a, b) {
  console.log(a - b);
}
subtract(10, 5); // Outputs 5

In the same vein, I’ll change the name of your function:

add(7, 9)

What should that print, and why might saying it should always print 2 + 1 be inorrect?

Well, you’re actually trying to do something that can’t be done. If you pass in parameters when you launch the function, then your solution should look like the first example with the addition, so you need a return a + b instead of the console.log. And pass in a and b as parameters of functionWithArgs

The goal of the challenge is to get functionWithArgs(7,9) to display the sum of 7 and 9 in the console, as well as (1,2). I’m wondering where I’m going wrong with my syntax.

The challenge is called “Passing values to functions with arguments”

Okay, so look at the first function, the example. What you have written is not similar at all.

Just to try to hammer home this point, if I executefunctionWithArgs(7,9) with your code, I get 3. If I execute functionWithArgs(50, 150), I get 3. If I execute functionWithArgs(250000000, 342578953), I get 3.

You have written in the body of that function that it will always print 3, no matter what the values are that go into the function. This is not the case with the example one