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 trialSteven Ossorio
1,706 PointsDon't understand where I'm going wrong.
I'll explain what I've been thinking though I don't get where I'm going wrong.
var results: [Int] = [1...10]
for multiplier in results {
print(results * 6)
}
// Enter your code below
var results: [Int] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
for multiplier in results {
print(results)
}
2 Answers
Nate Bird
7,999 PointsHi Steven,
You’ll need to create a blank results
array. Then loop through an array of 1 to 10 (you can set it first or just create it on the fly. Then you calculated the value and append it to the results array.
var results: [Int] = []
for number in 1...10 {
let multiplier = 6
let value = number * multiplier
results.append(value)
}
Jhoan Arango
14,575 PointsHello Steve:
You were close on your attempt.. Remember the challenge said to use a range, and not the empty array he gave you. This empty array is to append the results of the for in loop.
The first part of the challenge it tells you to create the signature of the for in loop, with a temporary constant named "multiplier".
for multiplier in 1...10 {
}
remember that the temporary constant goes after the "for" word. This constant is there to hold values for a brief moment while your code does something with it. In this case is being used as a multiplier.
Second part of the challenge you have to finish the code inside the body.
for multiplier in 1...10 {
results.append(multiplier * 6)
}
This is appending the result of a multiplication into the empty array. So every time the loops goes around, it multiplies, and then appends to the array.
So to make it a bit more clear:
for multiplier in 1...10 it grabs one number from the rage in this case 1 and assigns it to multiplier
results.append(multiplier * 6) Then multiplier is used to be multiplied by 6, and the result is then added to the array. And then the loop starts again, until it has no more numbers to grab from the range.
Hope this makes it a bit more clear.