Ruby Ruby Collections Ruby Hashes Working with Hash Keys

Stuck on: Ruby Collection Challenge Task 1

Using the has_key? method, check if the hash variable has a key called "calories". If it does, set a new variable called food to true.

I think the part "food == true" is fault. But I can't figure out how. Please help! :(

hash = { "name" => "Bread", "quantity" => 1, "calories" => 100 }
food == true

3 Answers

adam n
adam n
57,282 Points
  • You're checking to see if there's a "calories" key, but youre not instructing your program to do something if it has this key.
  • On line 3 you're checking to see if food is equal to true, but you havent defined a food variable in your script.

Let me know if that helps here

Sean Cedric Baart
Sean Cedric Baart
7,931 Points

Hey, There is not that much wrong with your code, all you have to do is put a "=" instead of the "==" and put the has_key? method inside an if statement.

Good luck

Thank you for the advice! :D solved it!