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 trialSam Belcher
3,719 PointsA little confused with for in loops
Can someone tel me what I'm doing wrong?
// Enter your code below
var results: [Int] = [6]
for multiplier in 1...10 {
print( (multiplier) * (results))
}
1 Answer
David Papandrew
8,386 PointsOk two things to tweak in order to pass this challenge:
1) The results array should be empty when you declare it. You will be appending results from the for-in loop to the results array.
2) In the body of the loop, you will use the append array method to append values to your results array. In this case, you will append the result of the multiplier * 6. The multiplier increments with each loop. So the first loop will be 1 * 6 (append that result). Second loop is 2 * 6, third loop is 3 * 6, etc.
var results: [Int] = []
for multiplier in 1...10 {
results.append(multiplier * 6)
}
If you want to see the values appended to the results Array, paste the above code into a Playground and then type "print(results)" after the for loop and you'll be able to see the appended values.