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
Kerem Kazan
Full Stack JavaScript Techdegree Student 5,280 Pointsfor loop not running
it says 'the for loop was not used' although it's there. what am i missing?
animals = ["dog", "cat", "horse", "goat"]
for i in 0..3 do
puts animals[i]
end
1 Answer
Chris Shaw
26,676 PointsHi Kerem,
At the moment your for loop isn't referencing the animals array but instead you have 0..3, instead this should be referencing animals so the for loop can iterate over each value.
One other thing is you're using the variable i within square brackets which isn't needed as ruby will automatically assign each array value to i therefore it would make far more sense to call it animal instead and use that in our puts statement.
With that said you would end up with something like the following which is what the challenge is expecting.
for animal in animals do
puts animal
end
Happy coding!
Kerem Kazan
Full Stack JavaScript Techdegree Student 5,280 PointsKerem Kazan
Full Stack JavaScript Techdegree Student 5,280 Pointsthanks chris. that was really helpful
Chris Shaw
26,676 PointsChris Shaw
26,676 PointsNo worries