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 Keys

I'm not sure why this code is not passing :(

If anyone could help me out with this problem that would be good! thx

hash.rb
hash = { "name" => "Bread", "quantity" => 1, "calories" => 100 }
hash.has_key?("calories")  if = true  "food" = hash

1 Answer

Samuel Webb
Samuel Webb
25,370 Points

Because you're not setting a variable called "food" to true if "hash" has the key "calories. That second line is all messed up:

food = true if hash.has_key?('calories')
Samuel Webb
Samuel Webb
25,370 Points

Also, the reason they put "food" in quotation marks in the question is to make sure you knew which word to use as your variable name. In your real code, the variable name doesn't need quotation marks.