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.

Oğulcan Girginc
24,848 PointsModify the "create_shopping_list" method to return a hash with the following keys and values:
def create_shopping_list
hash = {
"title" => "Grocery List",
"items" => []
}
end
Why the code above does work but the one below doesn't? Aren't they the same/similar?
def create_shopping_list
hash = {
title: "Grocery List",
items: []
}
end
Update:
The given error is :
Bummer! The create_shopping_list
method did not have a key called 'title' with the value of 'Grocery List'.

Oğulcan Girginc
24,848 PointsAdded the error! :)
2 Answers

Maximiliane Quel
Courses Plus Student 55,489 PointsHi Oğulcan,
the second code works on a console but not in the challenge, because the challenge specifically asks you to use the strings of 'title' and 'items' and not symbols with the same name as keys. Using symbols as keys is usually good practice. It is just not want the challenge was expecting :0)

Oğulcan Girginc
24,848 PointsThanks for the stating differences! :)

Alan Matthews
10,161 PointsThe create_shopping_list
methods should work, but I believe the error is due to the fact that hash
is scoped to those methods and cannot be accessed outside the methods. So it isn't an error per say, but it's probably not returning what you want. If you make a method like this:
def create_shopping_list
hash = {title: 'List', item: 'milk'}
puts hash[:title]
end
create_shopping_list
It should return List
. Hope this helps, I am not expert!

Oğulcan Girginc
24,848 PointsThanks! :)
Alan Matthews
10,161 PointsAlan Matthews
10,161 PointsThe above code works when I try it out in my console, could you post the error you are getting?