Ruby Ruby Collections Ruby Hashes Working with Hash Keys

I'm not sure why this code is not passing :(

If anyone could help me out with this problem that would be good! thx

hash.rb
hash = { "name" => "Bread", "quantity" => 1, "calories" => 100 }
hash.has_key?("calories")  if = true  "food" = hash

1 Answer

Samuel Webb
Samuel Webb
25,366 Points

Because you're not setting a variable called "food" to true if "hash" has the key "calories. That second line is all messed up:

food = true if hash.has_key?('calories')
Samuel Webb
Samuel Webb
25,366 Points

Also, the reason they put "food" in quotation marks in the question is to make sure you knew which word to use as your variable name. In your real code, the variable name doesn't need quotation marks.