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

Help with Solving the Hash Keys Challenge Question

I'm having trouble spotting what I'm missing to get my code working. Anyone spot how to fix?

hash = { "name" => "Bread", "quantity" => 1, "calories" => 100 } <p>if hash.has_key?("calories") == true </p> <p>puts "food" = true</p> <p>end</p>

2 Answers

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,443 Points

Hi Natalie,

By using "puts" you are telling Ruby to put a string to the screen, and this is not what the challenge wants. The challenge wants you to assign the boolean value of true to a new variable named "food" if the hash contains the value "calories."

So think of the logic this way: The variable "food" is now true because the hash contains "calories." This will translate into code like this:

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

Hope this makes sense. Keep Coding! :)

Thanks!