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

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,733 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!