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 trialJeanette Trudell
11,460 PointsPoint of answer = answer.to_i if kind == "number" in this program?
Why is this line of code included in this program? It is never used. If you passed "number" to the add method (add("What is the phone number?", "number")) I would understand why it was included. As the program is written, though, the phone numbers entered are simply strings that get printed out to the screen.
1 Answer
Garrett Carver
14,681 PointsYou're right, It's not being used in this case. It would be useful if the ask()
method ever needed to return an integer. For example, the program could ask the user "How many contacts would you like to add?". So you wold write:
ask("How many contacts would you like to add?", "number" )
Then you could change the program so it only asks the user for as many contacts as they specified.
candacemielke
6,466 Pointscandacemielke
6,466 PointsFor this kind of basic program, yes, it would be pointless to include that bit of code. However, this is a lesson on using these types of snippets in different situations. Including that was for the sake of the learning, I'm sure.