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 Loops Ruby Iteration The For Loop

Gareth Powell
PLUS
Gareth Powell
Courses Plus Student 7,016 Points

Help on challenge "Use a for loop to print each item in the animals array to the screen using the puts method."

Hi Everyone,

I am sure it is easy but I am struggling to pass this challenge after several different attempts. Here is my code - thanks in advance:

animals = ["dog", "cat", "horse", "goat"] for animals.array item puts "The current item is #{item}." end

for.rb
animals = ["dog", "cat", "horse", "goat"]
for animals.array item
  puts "The current item is #{item}."
end

4 Answers

Philip Benton
Philip Benton
1,378 Points

If you look back over the previous video that should help. Your answer should look like this:

animals = ["dog", "cat", "horse", "goat"]
for item in animals do
  puts "The current item is #{item}."
end
Gareth Powell
PLUS
Gareth Powell
Courses Plus Student 7,016 Points

Thanks Mauricio and Philip, much appreciated.

FYI, Philip's answer worked for me.

Cheers!

animals = ["dog", "cat", "horse", "goat"] animals.each { |a| puts "The current item is #{a}." }

Mars Epaecap
Mars Epaecap
5,110 Points

do you HAVE to type out the entire array? What if it has like thousands of items?