Ruby Ruby Collections Ruby Hashes Working with Hash Keys

Brian Patterson
Brian Patterson
19,586 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,129 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.