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.


Sebastian Giliberto
Sebastian Giliberto
1,809 Points

How in the world are we supposed to know this? :)

Using the values_at method, create an array called grocery_list with the value of the grocery_item hash at the "item" key.

The question sounds really easy but the answer is not.

this is the answer:

grocery_item = { "item" => "Bread", "quantity" => 1, "brand" => "Treehouse Bread Company" }
grocery_item["food"] = true if grocery_item.has_value?("Bread")
grocery_list = grocery_item.values_at("item")

how are we supposed to know that they are supposed to be if statements in there? I just feel really bad for my self when ever I cant get a challenge right, does that means i am not good a this? Thank you


4 Answers

Have you followed all the videos that come before the quiz - because if you have - they were all covered in the videos

Sebastian Giliberto
Sebastian Giliberto
1,809 Points

Yes I for surly have. The only thing that I did not get in that challenge is that I needed an if statement, I no for sure that I needed all of the other methods in there but I did not know that an if statement was needed for it.

Ben Wong
Ben Wong
19,426 Points

grocery_list = grocery_item.values_at(0)

grocery_item = { "item" => "Bread", "quantity" => 1, "brand" => "Treehouse Bread Company" } if grocery_item.has_value?("Bread") grocery_item["food"] = true end grocery_list = grocery_item.values_at("item")