Ruby Ruby Collections Ruby Hashes Working with Hash Keys

what is wrong with my code?

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

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

1 Answer

Martin Cornejo Saavedra
Martin Cornejo Saavedra
18,130 Points

The challenges asks for creating a variable, not adding a key to the hash.

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