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 trialJoshua Goss
5,714 Points"Try again!" That's all I get...
I've defined the methods need in order to push the hash value to the array correct?
def create_list
grocery_list = { 'title' => 'Grocery List', 'items' => [] }
end
def list_item
grocery_item = { 'title' => 'Bread', 'quantity' => 1 }
end
list = create_list()
list['items'].push(list_item())
1 Answer
Jeff Muday
Treehouse Moderator 28,722 PointsThat's a pretty cool solution. You look like you studied a functional-based programming paradigm.
The way the tests are written is simpler; it depends upon the mutable nature of the list inside the hash.
You simply want to add the grocery_item
to the end of the items
array contained in grocery_list
Try this piece of code. Good luck on your Ruby journey it's a cool language!
grocery_list = { 'title' => 'Grocery List', 'items' => [] }
grocery_item = { 'title' => 'Bread', 'quantity' => 1 }
grocery_list['items'].push(grocery_item)
Joshua Goss
5,714 PointsJoshua Goss
5,714 PointsGreat! Thank you Jeff :)