Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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...

shopping_list.rb
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 }

grocery_list['items'].push(grocery_item)

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: