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

This still is not working. Trying to create a hash if the statement is true.

Not sure what I'm doing wrong.

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

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

It asks you to use the has_value? method. Not the has_key? method. Try simply repacing the has_key? with has_value? Hope that helps!

Haha I've been so irritated with this and it was that simple. No idea how I kept missing that. Thank you sooo much!

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Well, to be honest it's almost never the giant logic flaws that are the problem. It's the missing quote or the misspelled variable. Sometimes it's just nice to have an extra set of eyes :) But, you're quite welcome!

Yes, definitely, I also noticed I misspelled "grocery" . Either the way it now works, thanks to your help.