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

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")