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 trialThomas Clark
6,649 PointsRuby quiz on hashes / methods
The quiz question is as follows:
Assign the value of the key name to the return value of the method get_name() in the contact hash. Assume that get_name() returns a string. Given the following:
contact_list = []
contact = {"name" => "", "phone_number" => "" }
my answer starts here:
contact_list = []
contact = {"name" => "", "phone_number" => "" }
def get_name() svalue = "Quiz" return svalue end
contact["name"] = get_name() puts contact["name"] puts contact.inspect
Which appears to work but the auto-grader states:
Bummer! The contact['name']
hash key did not have the value of the get_name()
method.
2 Answers
Maciej Czuchnowski
36,441 PointsYou are doing more than the exercise asks you to do. You have to assume that get_name was already defined somewhere and that you can use it in your program and it will return a string. The only line you need to add to the code provided by Treehouse is:
contact["name"] = get_name()
Thomas Clark
6,649 PointsThat works great Maciej. The question should be updated by author to read:
"Assign the value of the key name to the return value of the method get_name() in the contact hash. Assume that get_name() HAS ALREADY BEEN DEFINED and returns a string."
[uppercase means the change requested]
That would have saved me a half hour of hair pulling. :)
Maciej Czuchnowski
36,441 PointsI know what you mean, my first instinct was exactly the same in this exercise. You should definitely suggest it to support (you can contact them using the link on the right).