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

This challenge looks similar to the has_key? in an early challenge but get a "bummer" message.

What do I do here? Your help will be appreciated.

hash.rb
grocery_item = { "item" => "Bread", "quantity" => 1, "brand" => "Treehouse Bread Company" } 
food = true if hash.has_value?("Bread")  
end

2 Answers

A couple minor issues here. :)

  • You don't need an end. It would actually cause an error. Only use end when you're not using the inline way.
  • "food" is supposed to be a key in the hash, not a separate variable.
  • Lastly, you've said hash.has_value?('Bread'), but "hash" isn't defined anywhere! Try changing "hash" to the hash you've defined.

Here's the code:

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

Good luck! ~Alex

Thanks for the clear and concise answer to my question!