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 trialSimon Goldman
1,028 Pointsadding items to a list
not sure how to add it
grocery_list = { 'title' => 'Grocery List', 'items' => [] }
grocery_item = { 'title' => 'Bread', 'quantity' => 1 }
grocery_item.values_at("items")
1 Answer
Jennifer Nordell
Treehouse TeacherHi there! I'm going to start by giving some hints here and hope that you can figure it out from there.
-
grocery_list
contains an empty array at the keyitems
- the
push
method can be used to add agrocery_item
to this array - the grocery_item array can be referenced by using
grocery_list['items']
- push the
grocery_item
onto the items array
I hope this helps, but let me know if you're still stuck!
Simon Goldman
1,028 PointsSimon Goldman
1,028 Pointsgrocery_item.push (grocery_list["items"])
still stuck not sure how to write it
Jennifer Nordell
Treehouse TeacherJennifer Nordell
Treehouse TeacherOh close! So close but you've got it a bit backward. Take a look:
grocery_list['items'].push(grocery_item)
First, we say we're going to access the
items
array inside the grocery list. Then we push the grocery_item into the items list. Hope this helps!