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

Erik Bonn
Erik Bonn
3,624 Points

Appending a Hash to an Array.

This is part three of a three part question, in the first 2 parts it accepted these lines of code:

contact["name"] = get_name() contact["phone_number"] = get_phone_number()

I'm a little confused as to why treehouse says my part 1 answer is no longer correct after I try submitting things for part three where I haven't changed the contact["name"] line at all. I know my code is a little bit off, so any suggestions would help!

contact.rb
contact_list = []
def add_contact
contact = {"name" => "", "phone_number" => "" }
contact["name"] = get_name()
contact["phone_number"] = get_phone_number()
  contact_list.push(add_contact())
end

1 Answer

Kourosh Raeen
Kourosh Raeen
23,732 Points

The problem is that you are creating a method. Your code for the last part should be:

contact_list = []

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

contact['name'] = get_name()
contact['phone_number'] = get_phone_number()
contact_list.push(contact)
Erik Bonn
Erik Bonn
3,624 Points

Thank you! makes sense!