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 trial

Ruby Ruby Collections Build a Grocery List Program Working with Hashes That Contain Arrays

I don't understand what should I do here, I tried all the possible examples and still I can't pass...

I tried with grocery_list['items'] = grocery_item

and it still fails!

What else should I try ? Can't pass this...

grocery_list = { 'title' => 'Grocery List', 'items' => [] }
grocery_item = { 'title' => 'Bread', 'quantity' => 1 }

I have to include the grocery_item hash in the "items" value array from grocery_list...

2 Answers

After struggling to get it work, I finally realised that I was working with an Array and had to use .push to insert that hash in it.

grocery_list = { 'title' => 'Grocery List', 'items' => [] }
grocery_item = { 'title' => 'Bread', 'quantity' => 1 }


And success! I'll keep this in mind for my whole life :)

Awesome! :smile:

I was planning to reply your question, however, you already solve the issues, glad you found it.

Happy Coding!

Thank you Salman Akram Wish you the best! :smile: