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 Ruby Hashes Working with Hash Values

Task 2 of challenge. Task 1 is no longer correct?

everytime i enter the code it says task 1 is no longer correct. I have verified my code with others QA and cant seem to figure out what is going on?

grocery_item = { "item" => "Bread", "quantity" => 1, "brand" => "Treehouse Bread Company" } grocery_item["food"] = true if grocery_item.has_value?("Bread") grocery_list[β€˜items’].push(grocery_item)

hash.rb
grocery_item = { "item" => "Bread", "quantity" => 1, "brand" => "Treehouse Bread Company" }
grocery_item["food"] = true if grocery_item.has_value?("Bread")
grocery_list[β€˜items’].push(grocery_item)

1 Answer

Tobias Helmrich
Tobias Helmrich
31,602 Points

Hey Kent,

your code has a few mistakes in it. You're trying to access the grocery_list array but you haven't even created it yet. And even if you would've created it the way you're trying to access it is only possible with hashes but not with arrays (also note that you didn't use quotes but accent characters). The other problems is that you're pushing the whole hash grocery_item to the array instead of just filling it with the value at item with the values_at method that the challenge wants you to use. If you fix the mentioned problems you should end up with something like this:

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

I hope that helps. If you don't understand something or have further questions feel free to ask, good luck! :)