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.

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