Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Final quiz quandary - Intro to Programming

In the final quiz covering functions, the first question is this:

"What is the value of x given the below"

var f = function(a, b){
var c = a + b;
return c * 2;
}

var x = f(3, 4);

The problem is the examples we just went through mainly covered creating functions with strings, not variables. I cheated by piping the output of x into console.log (x=14), but for the life of me I don't know why the answer is what it was.

2 Answers

The function f takes two arguments a & b. Think of these arguments as placeholders for the real values you plan on passing into this function.

So in f(3,4) 3 == a & 4 == b, so if you substitute 3 for a and 4 for b in the function body you'll end up with c = 3 + 4 and the function returns the product of 7 * 2.

I hope that makes sense.

It took a few passes, but yeah that totally makes sense. I wish the last video went through this type of example instead of the Hello World/string arguments from the video.

But thanks Patrick, I really didn't want to press on until that one made sense. :)