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 trialLindsay Barrett
Python Web Development Techdegree Student 7,357 PointsRuby Loops
How can I solve this problem?
numbers = []
number = 0
loop do
number + 1
if numbers === numbers[2]
break
end
end
numbers.push(number)
2 Answers
Alexander Davison
65,469 PointsYou are doing a great job! However, you can't just say "number + 1", or Ruby will think you want the result of the number plus one. Instead, you have to do "number += 1". Second, there is no "===" operator in Ruby. That's only for JavaScript. You'll have to use the "==" operator. Lastly, I don't know why you did "numbers == numbers[2]", but you should get the length, like this: "numbers.count" or you also could do: "numbers.length", and see if it is equal to three. The code:
numbers = []
number = 0
# write your loop here
loop do
number += 1
numbers.push(number)
if numbers.count == 3
break
end
end
Hope that helps!
jcorum
71,830 PointsClose. Try this:
loop do
numbers.push(number)
number += 1
if numbers.length >= 3
break
end
end