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 trialJeremy Elsmore
1,020 PointsI need help on this question about For In Loops in Swift.
I'm not understanding what I'm supposed to do. Do I turn this into a dictionary?
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)")
}
This prints out the multipliers. What else is needed? The instructions are confusing.
This is what I thought it was asking for, but it says it's wrong.
results.append(6, 12, 18, 24, 30, 36, 42, 48, 54, 60)
1 Answer
Nathan Tallack
22,160 PointsWhat they are wanting you to do is to have a for loop populate the results array with the multiple results.
Consider my code example below with comments inline.
var results: [Int] = [] // This is the empty array that we will append to.
for multiplier in 1...10 { // Here we are using a closed range to make a list of numbers to loop over.
results.append(multiplier * 6) // Here we are appending the result of the multiplier to the array.
}
I hope this helps. Feel free to ask more questions if you have them. :)
Jeremy Elsmore
1,020 PointsJeremy Elsmore
1,020 PointsThanks for the clarification! Makes sense now.