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 trialcloud712
7,616 PointsCould someone point out the mistake I have here? Would greatly appreciate the help!
Not sure why the push method isn't working or what the error I'm getting is pointing to. Any help is greatly appreciated!
contact_list = []
contact = {"name" => "", "phone_number" => "" }
contact["name"].push(get_name)
1 Answer
Jennifer Nordell
Treehouse TeacherHi there, cloud712! I feel like you're overthinking this. We use the .push
when we want to add an item to an array. This is a hash. As the instructions indicate, they've created a custom method elsewhere called get_name()
. It's going to return a name as a string. For instance, it might return "Cloud". We just don't know. But we want to set the name to whatever it does return.
So I'm expecting:
contact["name"] = get_name()
This will call the method. The method returns a name as a string, and we assign it to the current "name" key of the hash which overwrites whatever was originally there.
Hope this helps!
cloud712
7,616 Pointscloud712
7,616 Pointsthank you!