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.
Mark Kohner1,760 Points
confused about using return values
In this example, cost_per_person is returned. I am a bit confused, though. It is given a variable name inside of the function -- and not defined outside. Okay. Why is it given a variable name at all?
In this particular example, there is no reason other than making the code easier to understand for the student. A much simpler code would have been "return total / number_of_people", but using a variable name clarifies what that result is supposed to be.
That being said, you can totally use variables in a function. Functions are like any other piece of code you will write, you will need to store data and label them with explicit names. While a new variable isn't totally necessary in this example, they will become critical as your code becomes more complex.