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 trialJabor Al thani
2,926 Pointsappend
I need help on the append function . Im trying to append my loops results into an empty array .
// Enter your code below
var results: [Int] = []
for numbers in 1...10 {
let multiplier = numbers * 6
multiplier.append([results])
}
1 Answer
Paolo Scamardella
24,828 PointsYou have two issues:
1 - The append method is on the array(results) and not on an integer(multiplier)
2 - When you append the value to an array, you just append the value without adding the brackets([])
var results: [Int] = []
// Also, I would change numbers variable to number,
// which in reality, you are appending a single number at a time and not an array of numbers.
// It reads better by saying for each number in 1 through 10 instead of for each numbers in 1 though 10
for numbers in 1...10 {
let multiplier = numbers * 6
results.append(multiplier)
}