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.

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!!