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

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.