Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Ruby Collections Ruby Hashes Working with Hash Values

Dino Tudor
Dino Tudor
1,767 Points

Please help to set a new key and value to the hash in this quiz.

I tried two ways to solve this quiz. At the console in workspaces the first worked fine, the second didn't show any error messages. Please help me to figure out this quiz. Thanks!

hash.rb
# this way it the key"food" does not have the value "true"

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



#second try, and i still can't get the key and value into the hash


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

1 Answer

Ian Bowers
Ian Bowers
3,665 Points

I think "true" in the description is referring to true and not a string of letters "true". Try removing the quotes and see what happens.

Dino Tudor
Dino Tudor
1,767 Points

Thanks Ian! That's it!