Ruby Ruby Collections Ruby Hashes Working with Hash Values

Ian Whitney
Ian Whitney
3,424 Points

Incorrect code for adding food w/ value of true to hash

unsure why my code is not working?

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

end

1 Answer

You are setting the value of grocery_item["food"] to the string of 'true' it should be a boolean true (no quotation marks):

grocery_item["food"] = true