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.

Ruby Ruby Collections Ruby Hashes Working with Hash Keys

Brian Patterson
Brian Patterson
19,588 Points

Not sure what is wrong

Not sure what is wrong.

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

1 Answer

Stephen Beckstrand
Stephen Beckstrand
11,169 Points

Hey Brian,

Your question does not seem to have much information, in fact, it does not seem like it even includes any of the code you have already tried. Going forward it would be best to include as much information as possible in your question to get the best possible answer.

In this challenge, it wants you to check if there is a key called "calories" within the hash called "hash" using the has.key method. If it does, it wants you to set a variable of food to "true". This is possible with the following code:

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

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

If this does not answer your question, just let us know and then provide as much detail as possible so we can better help you.