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 trialluke parker
489 PointsHaving trouble appending to array
I'm still not sure how to append to the array. Any ideas?
// Enter your code below
var results: [Int] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
for multiplier in 1...10 {
}
3 Answers
Steven Parker
231,269 PointsFirst, you don't want to place any values into the array before the loop starts. The code in the loop will fill the array in.
Your loop looks good, so now you could use the "append" method on the array to add a new element, giving it a value six times larger than the "multiplier".
So that would look like this:
var results: [Int] = []
for multiplier in 1...10 {
results.append(multiplier * 6)
}
luke parker
489 PointsCan you show me what that looks like?
Steven Parker
231,269 PointsOK, I expanded my answer.
luke parker
489 PointsThanks! I was so close!
Steven Parker
231,269 PointsGlad to help, "cousin". And happy coding!