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

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,860 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!