Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.


Jakob Wozniak
Jakob Wozniak
17,896 Points

Bug with "Working with Hash Keys" Challenge-

There seems to be a bug with this challenge; I've tried many different ways of adding the key value pair "food" => true, but every time I get an error message saying "Food was not found".

The objective is 'Using the has_key? method, check if the hash variable has a key called "calories". If it does, set a new variable called "food" to true.'

Here's my code.

hash = { "name" => "Bread", "quantity" => 1, "calories" => 100 }

if hash.has_key?("calories")
  hash["food"] = true

1 Answer

Jakob Wozniak
Jakob Wozniak
17,896 Points

Wow. Turns out it wanted a brand new variable called food, not a new key-value pair. I must say, that's extremely misleading, especially since food is in quotes (like it's wanting a string). I can't imagine why you wouldn't want that as a value pair; why would you have a general variable called food?! Maybe we_have_food, or hash_has_food.

Lol, I just wasted 20 minutes on this!