Ruby Ruby Collections Ruby Hashes Working with Hash Values

Christopher Zawisza
Christopher Zawisza
961 Points

Getting the correct value in a Hash

Hi! I'm trying to pass this challenge:

Using the has_value? method, check to see if the grocery_item hash has a value called "Bread". If it does, set a new key in the hash called "food" with the value of true.

It's telling me that "food" is not returning a value of true. When I run this in irb it works fine. I'm unsure what I might be missing here...

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

1 Answer

KRIS NIKOLAISEN
PRO
KRIS NIKOLAISEN
Pro Student 47,480 Points

true shouldn't be enclosed in quotes. That makes it a string instead of a boolean.