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

Ruby Loops adding contacts Task 1: I may have misunderstood something.

I think I may be misunderstanding the request of the task. I feel I understand the general nature here, but I am clearly missing something.

Looking at what I have done, can anyone help me see what part of the question I may be missing?

contact.rb
contact_list = []
def add_contact
    contact = {"name" => "", "phone_number" => "" }
  contact["name"] = get_name("What is the name?")
  return contact
end

2 Answers

Jeff Muday
MOD
Jeff Muday
Treehouse Moderator 28,717 Points

I totally see where you are going with this-- but they want something a little bit simpler. They are asking only for you to update the existing hash contact, and then push it onto the contact list. See below.

Good luck with Ruby it's a really useful language!

contact_list = []

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

contact["name"] = get_name()
contact["phone_number"] = get_phone_number()
contact_list.push(contact)

Doh! I did this to myself a few lessons ago by coding it to get the input referenced too. Thank you so much, Jeff!