7.2. Access by Index


#1

Hello,

Here is my code:

demo_array = [100, 200, 300, 400, 500]
demo_array[2]

but it did not print out to the console...

Which code will?


#2

Which method is used to print something to the console? You should already know two of them if you got this far. Don't hesitate to go back to previous lessons when you need to.


#3

Yes, I will look up a method which is used to print something in previous lessons. Thank you for your advice.


#4

I'v got it now.

demo_array = [100, 200, 300, 400, 500]
demo_array[2]
puts "300"

This code works.


#5

Of course it seems like it work since you ask puts to display 300.

Why don't you try passing demo_array[2] to puts instead?


#6

Codecademy liked my code. You know. Finished my lesson with it. Will still try passing demo_array[2] to puts.


#7

This code worked 2!!! Smart.

demo_array = [100, 200, 300, 400, 500]
puts demo_array[2]

So now we have 2 codes. Different ones.