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

Eliot Alderson
Eliot Alderson
2,152 Points

has_value? - Challenge not working

So i have asked whether it has a key of "bread" and then i am proceeding to updating the hash with a new key & value.

Hash = {"food" => "true"}

but it still fails, i tried to add the new key pair separately and then add it to the original but neither worked.

hash.rb
grocery_item = { "item" => "Bread", "quantity" => 1, "brand" => "Treehouse Bread Company", "food" => "true"}

grocery_item.has_value?("Bread")

1 Answer

Steven Parker
Steven Parker
230,995 Points

The test for the value needs to be part of an "if" statement that will control whether the other key is added or not.

The original contents of the hash should remain as they were originally if the test does not pass, so don't modify the line of code originally provided.