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 trialLiviu Tudor
7,061 Pointsdo I need to create a method?
for this I need to create a method?
grocery_list = { 'title' => 'Grocery List', 'items' => [] }
grocery_item = { 'title' => 'Bread', 'quantity' => 1 }
grocery_list['items'] = grocery_item
1 Answer
Sorin Pantis
5,138 PointsLiviu Tudor you don't need to create a method, but since your grocery_list
value for the items
key is an array, you need to add to that array using the push
method or using <<
. So your code would look like this:
grocery_list['items'].push(grocery_item)
or
grocery_list['items'] << grocery_item
Let me know if this does the trick for you! ?