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 trialAndrew Insley
7,014 PointsI though I got the loop principle, but this question has completely stumped me. Would really appreciate some help???????
I get the loop principles, the thing I am having trouble with is adding the values into the array.
Could really do with a hand to stop me going mad.
Thank you
numbers = []
number = 0
numbers[0] = number
1 Answer
Seth Reece
32,867 PointsHi Andrew,
Adding items to an array can be done with push. e.g. You could also use unshift to add to the beginning, or insert to add in a certain position, but I think push is fine for this task.
numbers = []
number = 0
loop do
numbers.push(number)
number += 1
if numbers.count >= 3
break
end
end
Andrew Insley
7,014 PointsAndrew Insley
7,014 PointsI would like to say I was close, but I wasn't. Thanks