Ruby Ruby Collections Ruby Hashes Working with Hash Values

what should be the output?

what should be the output?

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

1 Answer

Abdullah Hashim
Abdullah Hashim
4,546 Points

Hello!

It wants you to add another key/value ("food" => true) pair to the grocery_item hash if any of the values in the grocery_item hash is equal to "Bread".

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