Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript

Carson Clark
Carson Clark
2,159 Points

I do not understand how this function equals 14, please help!

How does the following function equate to 14? I'm very confused. Could anybody out there explain this to me?

Thanks

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

  var x = f(3, 4);

2 Answers

Louis Sankey
Louis Sankey
22,595 Points

yes, down at the bottom you are assigning the integers 3 and 4 to 'a' and 'b'.

You can now look at the second line like it says: var c = 3 + 4;

This is the same as saying: var c = 7;

Then, in the next line, it says: return c * 2;

This is saying: return 7 * 2;

Let me know if that doesn't clear things up and I will try explaining a different way.

Carson Clark
Carson Clark
2,159 Points

Thank you. I don't know what the heck was wrong with me but for some reason I thought I was supposed to multiply 3 and 4.. wow.

thanks again.