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
Jason Anders
Treehouse Moderator 145,036 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! :)