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 Ruby Arrays Accessing Items in Arrays

I've been stuck on this one and I need some help.

I've been defining the variable first_item and putting grocery_list [0] = first_item then end.

array.rb
grocery_list = ["milk", "eggs", "bread", "ice cream", "potatoes", "pie"]

def first_item
  grocery_list[0] = first_item 

end

1 Answer

Angela Visnesky
Angela Visnesky
20,927 Points

Hi William! You are making things a little more complicated than you need to.

first_item = grocery_list[0]

This will put you on the path to finishing the challenge. I hope this helps!

Scott Wyngarden
Scott Wyngarden
Courses Plus Student 16,700 Points

And to add a little more information, when you're assigning to a variable, the variable goes on the left side of the equals sign, and the value (or where you're getting the value from) goes on the right. so given a variable called my_variable, any time you want to assign to it, it your code should look something like this

my_variable = 5

or

my_variable = grocery_list[0]

The code you wrote tried assigning whatever first_item holds to the first element of your array. In short, you just had your syntax backwards

Hey thanks for the help I appreciate it.