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 Create a Method That Returns a Hash

Eric Carter
Eric Carter
2,130 Points

What is the challenge task asking for?

I did what the prompt asked for but it doesn't seem to be registering with what the task is asking for?

shopping_list.rb
def create_shopping_list
  print "What is the list's name?"
  name = gets.chomp

  hash = {"name" => name, "items" => Array.new }
  return hash
end

2 Answers

Manish Giri
Manish Giri
16,266 Points

The challenge linked in your question is this -

Create a method named "create_shopping_list" that returns a hash. It does not need to ask for a name or get anything from standard input.

For that you just need to return a new Hash from the method -

def create_shopping_list
  Hash.new
end
Eric Carter
Eric Carter
2,130 Points

Ahhhh okay okay thanks a lot!

Ari Misha
Ari Misha
19,268 Points

Hiya there! The challenge just wants you to create a method called create_shopping_list and it doesnt need to return anything other than an empty hash. Its pretty straightforward , but i'll still attach the code with my answer.

def create_shopping_list
  {}
end

~ Ari

Eric Carter
Eric Carter
2,130 Points

Ohhhh okay it went right over my head! Thanks a lot.