Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Ruby Collections Ruby Hashes Working with Hash Keys

'If it does, set a new variable called food to true' - I am unable to perform this section of the task.

I tried all the possible ways to set food to tue in this task but cannot.

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

2 Answers

Hi there,

You can do this on one line, or multiple. The conditional test uses has_key? on hash using dot notation. Pass in "calories" either in the brackets or without them.

Around that, you can either use an if and end before & after, setting food = true inside that block. Or, you can just do this on one line by saying food = true if condition - the condition is the test above.

I hope that helps,

Steve.

thank you so much

No problem! :+1: