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 trialBrant Faulkner
7,921 PointsStuck on Stage 2 of Ruby Hashes
My current code is trying to make anther key and value.
I have also tried the second line of the if statement: food = true "food" = "true" etc.
I am not sure what it wants me to do.
Thanks
hash = { "name" => "Bread", "quantity" => 1, "calories" => 100 }
If
hash.has_key?("calories")
hash["food"] = "true"
end
1 Answer
Maciej Czuchnowski
36,441 PointsWell, the new code should look something like this:
if hash.has_key?("calories")
food = true;
end
Notice that if
keyword should be in the same line as the condition and food
needs to be just a variable, not a key in the hash - "set a new variable called "food" to true" - also, names of variables should not be in double quotes, same goes for boolean values.
Brant Faulkner
7,921 PointsBrant Faulkner
7,921 PointsThanks for the assistance. The explanation was helpful.