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 trialCarl Smith
8,185 PointsNot understanding these instructions
I'm not sure how to perform the correct task.
// Enter your code below
var results: [Int] = [1, 2, 3, 4, 5, 6]
for results in 1...10 {
let multiplier
}
results.append(multiplier)
1 Answer
Steven Deutsch
21,046 PointsHey Carl Smith,
Let's break this problem down. First, the challenge is asking you to use a for loop to iterate over a range. This is a range of 1 through 10, which we can declare using the closed range operator as 1...10. Now for each iteration of the loop, we need a local constant to store the value from the range. The challenge is asking us to name this constant multiplier.
Second, now we can setup the body of our for loop. Inside the loop body, we want to take the value of multiplier times six and use the append method to add the product of that expression to our results array.
Keep in mind, that for each iteration of the loop, the value inside of multiplier changes. For the first execution (iteration), the value is 1. The next time it iterates, the value of multiplier will be 2. It will continue to increment for each iteration until it reaches the end of the range. The loop will then cease its execution.
// Enter your code below
var results: [Int] = []
for multiplier in 1...10 {
results.append(multiplier * 6)
}
Good Luck