Ruby Ruby Loops Ruby Iteration The For Loop

Gareth Powell
PRO
Gareth Powell
Pro 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
PRO
Gareth Powell
Pro 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?