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 trialFrancisco Cunha
3,017 PointsCan someone please tell me how can I append the "contact" hash to the array "contact_list"? I am stuck at this for ages
Task 3 of "Assigning Hash Values" in the Ruby Loops Module. I have tried "contact_list << contact" and contact_list.push(contact), but none of them worked...
contact_list = []
contact = {"name" => get_name(), "phone_number" => get_phone_number() }
def get_name()
return "any string"
end
def get_phone_number()
return "any string"
end
1 Answer
Jason Anders
Treehouse Moderator 145,860 PointsHi Francisco,
You are right with the .push method, but the reason you are not able to pass is because you added much more than what the challenge asked for.
When you are the assigning values to the keys, the challenge tells you to "Assume that get_name() returns a string." It doesn't tell you to define a method that returns a string. So even the your code is technically correct, it is wrong based on what the challenge asked.
Just remove all the methods you created and you will be good to go. The completed code should be exactly this:
contact_list = []
contact = {"name" => get_name(), "phone_number" => get_phone_number() }
contact_list.push(contact)
Keep Coding! :)
Francisco Cunha
3,017 PointsFrancisco Cunha
3,017 PointsThanks Jason! Great advice!