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 trial

Ruby Ruby Collections Build a Grocery List Program Method Returns with Hashes and Arrays

Am I overthinking this challenge with this code?

Again, arrays seem to be so confusing for me. Either I'm completely not getting the instructions, overthinking it, or just darn confused by the whole thing.

The only error message I get on Treehouse is "Try again!". Not helpful at all. Can anyone have a look and tell me what's wrong? I tried running it on Workspace and it does print the array so I'm really really really confused.

shopping_list.rb
def create_shopping_list
  title = "Grocery List"
  items = Array.new

  puts "title: #{title}"
  puts "items:" + items

  return create_shopping_list
end

1 Answer

Grace Kelly
Grace Kelly
33,990 Points

Hi Nikki, the challenge requires for you to only return a hash inside the create_shopping_list method, you don't need to output anything to the screen. We create a hash by doing the following:

hash = {"key" => "value"}

So by applying this code you can assign the keys "title" and "items" with their values "Grocery List" and an empty array (Array.new) for example {"title" => "Grocery List"}. Also remember that you need to return this hash :)

Hope that helps!!

I guess I am overthinking it. :P Thanks for the help!

Grace Kelly
Grace Kelly
33,990 Points

no worries!! glad to help!!