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 trialBrian Patterson
19,588 PointsSo why is this giving me an error?
def create_shopping_list hash = { 'title' => Grocery List, 'items' => Array.new } return hash end
def create_shopping_list
hash = { 'title' => Grocery List, 'items' => Array.new }
return hash
end
2 Answers
Rick Buffington
8,146 PointsYou are almost there. Your syntax for the hash is correct, however you are missing some quotes/apostrophes around the actual title of the list. Ruby is stuck on the word Grocery and then domino's after that.
hash = { 'title' => 'Grocery List', 'items' => Array.new
Rick Buffington
8,146 PointsThe difference is that he is assigning what you type in the console to a variable named "name" - he then uses that variable in the hash. You are are trying to assign a string. Example:
name = "John" # We are assigning a string to name (you could use gets.chomp like the video)
hash = { "name" => name, "items" => Array.new } # Here, we use the key "name" and assign it the variable name
# Instead of using a string assignment for value, he is using a variable
The above is the same thing as this without using a variable (like what you were trying to do):
hash = { "name" => "John", "items" => Array.new }
Brian Patterson
19,588 PointsAh I see. The variable name is name = gets.chomp
Brian Patterson
19,588 PointsBrian Patterson
19,588 PointsSo why in the Shopping list example he does not put name in quotes ? ' def create_list print "What is the list name ? " name = gets.chomp hash = {"name" => name, "items" => Array.new } return hash end '