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.
Chaya Feigelstock2,429 Points
Why is the integer that is passed through "age" automatically converted into a string? What is the logic behind it?
Craig briefly mentioned when going through the code at the end that the integer passed through "age" is automatically converted into a string but didn't explain why?
Jennifer NordellTreehouse Teacher
But here, we need the age to be a number we can do math on so we have to tell it to take what the user sends in (which, again, is a string) and turn it into an integer, which is a number we can perform math on later.
And think about it for a minute. Most of the time when we're asking a user for information, we're really wanting a string (even when it's a number). We might ask for their name, address, zipcode, state, email address and more. While some of those may contain numbers, the numbers we actually need to use math on are relatively limited so it makes sense to have the information coming in from the user a string by default and then change it to a number if we need it that way
Hope this helps!