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 trialBethel Loh
477 PointsSwift 3 collections and control flow: coding challenge for in loop
Hi everyone,
Does anyone know the exact code to get through this challenge?
Cheers
// Enter your code below
var results: [Int] = [1,2,3,4,5,6,7,8,9,10]
for multiplier in 1...10{
results.append(multiplier * 6)
}
2 Answers
Jeff McDivitt
23,970 PointsYou do not need to add anything to the code that was provided for the task. Just leave it the way that it is and your code will pass and is correct
var results: [Int] = []
for multiplier in 1...10 {
results.append(multiplier * 6)
}
Jenny Dogan
4,595 PointsCan you explain the logic of declaring the results variable first then performing the math? Also, do you not use interpolation here because multiplier is also an integer? Thanks!
Jeff McDivitt
23,970 PointsThe results variable is just an empty array to hold the multiplier times 6. Also you are correct as you don't need string interpolation because you are not dealing with a string
Eunice Torres
2,278 PointsEunice Torres
2,278 Pointsvar results: [Int] = []
for multiplier in 1...10 { results.append(multiplier * 6) }
Do not add the integers in the variable since this is done in the loop.