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 trialRobert Newton
1,339 Pointsstuck on ruby collections
I know I'm missing something, but I can't figure what it is. Any ideas?
grocery_item = { "item" => "Bread", "quantity" => 1, "brand" => "Treehouse Bread Company" }
if (grocery_item.has_value?("Bread"))
puts grocery_item.unshift["food" => true]
end
3 Answers
Justin Horner
Treehouse Guest TeacherHello Robert,
Inside your if condition try assigning "food" to true this way without puts.
grocery_item["food"] = true
I hope this helps.
Salman Akram
Courses Plus Student 40,065 PointsHi Robert,
Seems very close but I think Jason Seifer already explained about "store" - @4:08. Other thing is to remove some brackets and don't have to use "puts" that will do automatically by using store method to add key/value to the hash.
Example:
grocery_item = { "item" => "Bread", "quantity" => 1, "brand" => "Treehouse Bread Company" }
if grocery_item.has_value?("Bread")
grocery_item.store("food", true)
end
Hope that helps
Robert Newton
1,339 PointsYes It did work! Thank you Justin. Now I'm confuse on why my method didn't work. I'll look up the 'store' method right after this Salman. Thank you both.
Justin Horner
Treehouse Guest TeacherYou're welcome!
Salman Akram
Courses Plus Student 40,065 PointsAwesome, happy coding!