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 Assigning Hash Values From Methods

Alicja Dul
Alicja Dul
8,589 Points

Ruby loops. Challenge 1 of 3. I can not do it..

Please, could someone provide me the right answer?

regards

contact.rb
contact_list = []

def get_name
contact = {"name" => "", "phone_number" => "" }
contact['name'] = get_name.value

end

1 Answer

Hi Alicja,

You're pretty close. The question in the exercise says the method get_name has already been created somewhere else. The teacher isn't showing the method but we know it exists. So you won't need the def get_name here.

Also, we don't need to specify value for the get_name method. You can truncate that piece of the code and simplify it.

So the only part you have to add should look something like this:

contact['name'] = get_name

Cheers!

Alicja Dul
Alicja Dul
8,589 Points

Thank you! finally...

contact_list = []

contact = {"name" => "", "phone_number" => "" }

contact['name'] = get_name