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 trialJP Hrubant
4,108 Points'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 = { "name" => "Bread", "quantity" => 1, "calories" => 100 }
hash.has_key?("calories")
hash.store("food", "true")
2 Answers
Steve Hunter
57,712 PointsHi 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.
JP Hrubant
4,108 Pointsthank you so much
Steve Hunter
57,712 PointsNo problem!