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 trialAlex Ross
3,091 PointsFrom the lesson I can still not understand how to limit the loop to only multiplying 1 - 10
The challenge is telling me I have to make sure only the results for 1 - 10 are shown, from what I can tell I am doing it correctly as the lesson taught.
// Enter your code below
var results: [Int] = [1,2,3,4,5,6,7,8,9,10]
for multiplier in 1...10 {
print(multiplier * 6)
}
1 Answer
Thomas Dobson
7,511 PointsAlex,
The task asks that:
Once you have a value, append it to the results array. This way once the for loop has iterated over the entire range, the array will contain the first 10 multiples of 6.
You filled the array with incorrect values (1-10). We can add values to the array with the append method. We want to append multiplier * 6. Like so:
var results: [Int] = []
for multiplier in 1...10 {
results.append(multiplier*6)
}
we can verify the contents of our array:
results //returns [6, 12, 18, 24, 30, 36, 42, 48, 54, 60]
I hope this helps!
Alex Ross
3,091 PointsAlex Ross
3,091 PointsThank you Thomas, I didn't realize having my values set in the results variable was incorrect.