Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

jay niceness
7,406 Pointsseriously confused... asking to create simple method "create_shopping_list" and only return a hash... not working...
in the build a grocery list program, stage 3 challenge... it asks for a simple method called "create_shopping_list" with no standard inputs, just return the hash...
def create_shopping_list
hash = { "name" => name }
return hash end
what's wrong with this code?
def create_shopping_list
hash = { "name" => name, "items" => Array.new }
return hash
end
4 Answers

ARNOLD SANDERS
5,266 PointsI would write it like this:
def create_shopping_list
hash = Hash.new
return hash
end
and then call it:
create_shopping_list
William Li
Courses Plus Student 26,865 PointsThis is actually pretty simple, it just ask you to return a hash, any hash would do, including an empty hash.
def create_shopping_list
{}
end
And the problem of your code is this line "name" => name
, you'll get a NameError exception because name
is undefined.

jay niceness
7,406 Pointsgot it thanks!

Ivan Kusakovic
12,197 PointsI have losted at making grocery list :(