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 trialWilliam Hartvedt Skogstad
5,857 PointsCan't understand what I should do in this Code Challenge...
Challenge Task 2 of 2
Inside the body of the loop, we're going to use the multiplier to get the multiple of 6. For example, if the multiplier is 1, then the multiple is 1 times 6, which is equal to 6.
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.
// Enter your code below
var results: [Int] = [6]
for multiplier in results {
}
4 Answers
Richard Lu
20,185 PointsHi William,
The challenge wants you to iterate over the numbers from 1 to 10.
"Your task for this step is to create a for in loop that iterates over a range. Multiplication tables typically range from 1 to 10 (with 10 included) so the range you are iterating over should go from 1 to 10."
In order to do that you'll need to make a for loop like this:
for multiplier in 1...10 { // 1 to 10 is the range
}
To calculate the first 10 multiples of 6, you need to multiply the numbers 1 through 10 with the number 6.
for multiplier in 1...10 {
multiplier * 6
}
The challenge also wants you to append the values onto result. Eventually you'll have a solution like this:
for multiplier in 1...10 {
results.append(multiplier * 6)
}
Happy coding! :)
td999999999
2,205 PointsI am still getting an error saying that I am not containing the first 10 multiples. I am using:
// 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) }
Tashi Tsering
497 PointsI was stuck for 2 hours on this code challenge. The answer is
var results: [Int] = [] for multiplier in 1...10{ results.append(multiplier * 6) }
Hope this helps.
Tyler Draughn
1,520 PointsI don't remember going over how to do that. Can anyone direct me to where we went over that (results.append)?
Kevin Perez
iOS Development with Swift Techdegree Student 1,030 PointsRight? I don't remember this being taught in the for in loop vid...
William Hartvedt Skogstad
5,857 PointsWilliam Hartvedt Skogstad
5,857 PointsAhh thanks a lot..! Have been stuck on this for a day, going back to previous videos to try to grasp what I should be doing. Your answer helped a ton!
Richard Lu
20,185 PointsRichard Lu
20,185 PointsMy pleasure William! I'm always looking to help! :D
- Rich