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

[solved] Build a Grocery List Program challenge.

I am stuck on this challenge, any tips on where I am going wrong would be appreciated.

I have also noticed that through these Ruby challenges the instructors use of single vs double quotes appears random much of the time. My current understanding is that one should use double quotes when the string needs to be interpolated.

But I am not sure when we should be using single quotes, or no quotes. Any guidance on that would be awesome too.

shopping_list.rb
def create_shopping_list
  hash = { 'title' = "Grocery List", 'items' => Array.new}
  return hash
end
Ryan Trimble
Ryan Trimble
15,559 Points

Hi there Brant,

To assign a value to a key in a hash, you need to use the => symbol. You have it on your "Items" key, but the "title" key only has an = symbol.

 def create_shopping_list
  hash = { 'title' = "Grocery List", 'items' => Array.new}
  return hash
end

should be:

 def create_shopping_list
  hash = { 'title' => "Grocery List", 'items' => Array.new}
  return hash
end

Looks OK otherwise!

As for the single vs. double quotes question, you seem to have an understanding for it. Double quotes are used when an variable needs to be interpolated.

Brant Faulkner I added "[solved]" to your title since Ryan Trimble's suggestion should solve the issue you're having. Next time post your response as an answer Ryan so we can give you some points for it! :)

Thanks Ryan. That was it.

Funny how a typo can create doubt in my understanding of the material. Will keep that in mind going forward.

1 Answer

J.D. Sandifer
J.D. Sandifer
18,813 Points

Reposting the solution above as an answer so it doesn't show up as unanswered:

To assign a value to a key in a hash, you need to use the => symbol. You have it on your "Items" key, but the "title" key only has an = symbol.