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 trialCody Perryman
4,209 PointsWhen I run my code in Xcode, it appears to answer the question, but not sure why I can't move forward... Thoughts?
I am not understanding what I am doing wrong. My for in loop takes the multiplier and iterates over the array and then multiplies by 6. I then append the answer to the array. When run results, it has appended the correct answer to the array. I don't understand what I am doing wrong. Any help would be greatly appreciated.
// Enter your code below
var results: [Int] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
for multiplier in results {
print("\(multiplier) times 6 is equal to \(multiplier * 6)")
results.append(multiplier * 6)
}
results
1 Answer
Damien Watson
27,419 PointsHi Cody,
Your array should be defined as blank, and then you loop from 1 to 10, adding the result into the array. This means your array will contain 10 answers, where yours would contain 20. Try this code:
// Enter your code below
var results: [Int] = []
for multiplier in 1...10 {
print("\(multiplier) times 6 is equal to \(multiplier * 6)")
results.append(multiplier * 6)
}
Cody Perryman
4,209 PointsCody Perryman
4,209 PointsThank you so much for the help! Makes sense :)