Ruby Ruby Collections Ruby Hashes Working with Hash Values

Tom Spencer
Tom Spencer
1,648 Points

i cant figure this question out. please help

i cant get this code challenge please help

grocery_item = { "item" => "Bread", "quantity" => 1, "brand" => "Treehouse Bread Company" }

if grocery_item.has_value?("Bread")
grocery_item.merge({:food => true })

1 Answer

Tabatha Trahan
Tabatha Trahan
16,256 Points

It looks like your issue is with adding the new key/value pair to your grocery_list hash. If you want to add a new key/value pair, all you need to do is type the name of the hash, opening square bracket, name of key, closing square bracket, then an assignment operator, then the value:

grocery_list["food"] = true