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

Andrew Ackerman
Andrew Ackerman
8,347 Points

Needing help with Hash Values.

Hi, I'm to entirely sure where I'm going wrong here. I'm very sure i've used a similar code before to do the same but for Hash Keys, I'm really appreciate some direction as to what I'm doing wrong.

Thank you in advance!

hash.rb
grocery_item = { "item" => "Bread", "quantity" => 1, "brand" => "Treehouse Bread Company" }
if hash.has_value?("bread")
  hash.store("food", true)
end
Andrew Ackerman
Andrew Ackerman
8,347 Points

I realise now that my hash was incorrectly named and should in fact be "grocery_list", but the rest is still not working.

2 Answers

Jean Malan
Jean Malan
10,781 Points

If hash.has_value?(β€œBread”)

Make sure your bread has a capitalized B as it is case sensitive.