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