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 trialLeonardo Escalante
3,190 PointsLoop construct
Plese help because with these code because I haven't found the error.
loop number numbers = [] number = 0 numbers["number"] number += 1 break if number = 3 end end
Thanks for your help.
loop number
numbers = []
number = 0
numbers["number"]
number += 1
break if number = 3
end
end
2 Answers
Maximiliane Quel
Courses Plus Student 55,489 PointsThere are a couple of issues. You are not adding to the array. There are a few methods to insert a number into an array. You can use the push method or a double less than sign which is synonymous. When you try to set the condition you are using an assignment instead of a comparison operator. You have two end and no do keyword. You are not checking the length of the array but instead assigning three to the variable ...
Here is an example of what your code could look like:
numbers = []
number = 0
# write your loop here
loop do
numbers << number
number += 1
break if numbers.length == 3
end
Leonardo Escalante
3,190 PointsThanks a lot!
Maximiliane Quel
Courses Plus Student 55,489 Pointsno worries :0)
Kirill Lofichenko
10,761 PointsKirill Lofichenko
10,761 PointsYou are missing the word "do" after loop. The correct use of loop construct would look like this: loop do end