Ruby Ruby Collections Ruby Hashes Working with Hash Values

Jason Widjaja
Jason Widjaja
7,904 Points

what is wrong with my code

idk what is wrong i did the same exact thing for the previous part and got it right

hash.rb
grocery_item = { "item" => "Bread", "quantity" => 1, "brand" => "Treehouse Bread Company" }
food = grocery_item.has_value?("Bread")
Johnathan Guzman
Johnathan Guzman
Treehouse Moderator 7,432 Points

Hey Jason,

For this challenge, we need to add a key and value to the hash - we can do this in two way:

1) using the .store method :

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

if grocery_item.has_value?("Bread")
  grocery_item.store("food", true)
end

Or

2) directly add the desired pairs as followed:

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

if grocery_item.has_value?('Bread')
  grocery_item["food"] = true
end

I prefer method number 1.

I hope this helps.