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 trialRon Chan
10,987 PointsCode challenge 1 of 3
The question asked to:
"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."
So contact is a hash given by: contact = {"name" => "", "phone_number" => "" }
The return value of the method get_name() should return the value of the key "name" in the "contact" hash. So I did this:
def get_name return contact["name"] end
Which is the most literal answer to what was asked.
I am guessing I did not understand the question correctly or I have given an answer out of context since it is the first question out of 3. Can anyone who has completed the challenge explain what I should have done?
1 Answer
Maciej Czuchnowski
36,441 PointsThe get_name
method is already defined somewhere, you just want to use it and assign its return value to the hash's name
key:
contact['name'] = get_name()
Ron Chan
10,987 PointsRon Chan
10,987 PointsThanks Maciej, I appreciate it. One more question: You can tell that just from this error message?
The
contact['name']
hash key did not have the value of theget_name()
method.Maciej Czuchnowski
36,441 PointsMaciej Czuchnowski
36,441 PointsWell, yes, but I can also tell it from the question they asked ;). I'm used to these form of questions. It gets easier when you see enough of them.