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 with appending array
What is wrong with my code? Any ideas?
// Enter your code below
var results: [Int] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
for multiplier in 1...10 {
print("\(multiplier) times 6 is equal to \(multiplier*6)")
}
1 Answer
Jhoan Arango
14,575 PointsHey There :
So, you are close. Few things you need to change. The results array needs to be empty when you first declare it. Then in the for in loop, you will add values to it as you iterate. Also, in the body of the loop, the challenge is not asking to do a print, but to append the value of the result into the "result" array.
Here take a look at this:
// Empty array
var results: [Int] = []
for multiplier in 1...10 {
let result = multiplier * 6
// Append the result into the array
results.append(result)
}
Hope this helps you