Ruby Ruby Collections Ruby Hashes Working with Hash Values

Andrew Ackerman
Andrew Ackerman
7,752 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
7,752 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.