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 trialAkosua Kernizan
19,994 Pointsthe ruby loop challenge 1
I'm confused as to what I am doing wrong. Please help! thanks
numbers = []
number = 0
# write your loop here
loop do
numbers << number
number += 1
if numbers > 3
break
end
end
1 Answer
Vitor Oliveira
6,766 Points1) If you want to stop your loop when your number >= 3, you should do it:
numbers = []
number = 0
loop do
numbers << number
number += 1
break if number >= 3
end
2) If you want to stop your loop when your numbers.length >= 3, you should do it:
numbers = []
number = 0
loop do
numbers << number
number += 1
break if numbers.length >= 3
end
Both codes work in this exercise, because when number.length >= 3 or number >= 3, the numbers array has more than 3 items.
Akosua Kernizan
19,994 PointsAkosua Kernizan
19,994 Pointsthanks that was really helpful
Shaii Ong
3,078 PointsShaii Ong
3,078 PointsI had the same problem. This was helpful! Thank you, :)