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 trialDana Weiss
PHP Development Techdegree Graduate 22,294 PointsRuby Hashes: It keeps looking for a key I'm not asking it to look for!
grocery_item = { "item" => "Bread", "quantity" => 1, "brand" => "Treehouse Bread Company" }
grocery_list = grocery_item.values_at("item")
Result: Bummer!Β The key food
was not found in the grocery_item
hash.
grocery_item = { "item" => "Bread", "quantity" => 1, "brand" => "Treehouse Bread Company" }
grocery_list = grocery_item.values_at("item")
2 Answers
William Li
Courses Plus Student 26,868 PointsYou should use has_value?
method on the grocery_item Hash to check if it contains value "Bread" , and you should write a conditional clause to do that.
grocery_item = { "item" => "Bread", "quantity" => 1, "brand" => "Treehouse Bread Company" }
if grocery_item.has_value?("Bread")
# set a new key in the hash called "food" with the value of true.
end
Replace the comment section w/ your own code to pass the challenge.
Dana Weiss
PHP Development Techdegree Graduate 22,294 Pointsah I see. After I completed that step the directions no longer included that so I deleted it! Thanks!
William Li
Courses Plus Student 26,868 PointsGenerally speaking, for a multi-parts code challenge, do NOT modify/delete the code written during the previous parts unless the current challenge description asks you to do so explicitly. The reason for that is because every time you click the Check Work button, The test cases always checks for the correctness of all the code you've written so far.