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

Rafael Samsara
Rafael Samsara
8,657 Points

I think that this challenge is still buggy.

Ruby Collections code challenge 1 of 1 adding grocery_item to grocery_list "item" array answer: grocery_list = grocery_item.values_at("items") However, it will fail no matter what alterations/refreshes I attempt. I've read that this has been brought to attention previously; should I skip this or is there a way to override the error to pass? Would love some help on this. Thank you

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

grocery_list = grocery_item.values_at("items")

2 Answers

William Li
PLUS
William Li
Courses Plus Student 26,857 Points

Hi there, the challenge, as it's right now, has not bug.

The problem here is that in your solution grocery_list = grocery_item.values_at("items"), the assignment operator = was used on grocery_list hash, doing so will assign an entirely new value to it, which isn't what the challenge is asking for.

The code challenge essentially wants you to retrieve the Array value associated with the items key from the grocery_list, then append grocery_item hash to the end of the Array.

One way to accomplish that is by using the push method in the Array class.

grocery_list['items'].push(grocery_item)

The use of push method was covered in this lecture.

Rafael Samsara
Rafael Samsara
8,657 Points

Hah! Woops, of course it does. Thanks for getting back to me so quick William- I must have not understood the question(i've been using the push method for sometime in my own projects!). Anyway, glad the challenge isn't bugged; now I can complete it! Have a good one :)