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 trialCaleb Kleveter
Treehouse Moderator 37,862 PointsMethod returns with hashes and arrays.
I feel like I should be writing more code, but I'm not sure. Here is the instructions (I'm on step 1):
"Modify the "create_shopping_list" method to return a hash with the following keys and values: 'title': A string with the value "Grocery List" 'items': An empty array"
shopping_list.rb
def create_shopping_list
puts "Title: " + "Grocery List"
puts "Items: " + [].to_s
end
2 Answers
Jose Rosado
3,090 PointsCaleb,
Remember that create_shopping_list
method should return a Hash.
def create_shopping_list
# hashes are created with brackets {}. E.G: new_hash = {}
hash = {
"title" => "Grocery List", # this is a key / value pair. In this case, "title" is the key and "Grocery List" is the value
"items" => [] # the key 'item' is an empty array.
}
end
Caleb Kleveter
Treehouse Moderator 37,862 PointsThanks for your help Jose!
Jose Rosado
3,090 PointsJose Rosado
3,090 PointsAlso, you can use numbers and symbols as the key.
Read this to understand Hashes better.