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 trialjay 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,868 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 :(