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 trial

Ruby Ruby Loops Build a Simple Contact List Part 2: Adding Contacts

Ron Chan
Ron Chan
10,987 Points

Code 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
Maciej Czuchnowski
36,441 Points

The 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
Ron Chan
10,987 Points

Thanks 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 the get_name() method.

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

Well, 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.