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 trialChris Howie
13,216 PointsStuck on the second part of the For In Challenge
I am not sure how to get the For In loop printed values and append them to the array.
// Enter your code below
var results: [Int] = []
for multiplier in 1...10 {
print("\(multiplier) times 6 is equal to \(multiplier * 6)")
}
2 Answers
Jhoan Arango
14,575 PointsHey:
This one is a simple, but sometimes hard to understand from the requirements.
var results: [Int] = []
for multiplier in 1...10 {
var result = multiplier * 6 // Multiplying by 6
results.append(result) // Appending results to array
}
So we want to multiply the constant multiplier by 6 and add that result to a variable, and then appended to the array.
This is one way to do it. You can also do it this way.
var results: [Int] = []
for multiplier in 1...10 {
results.append(multiplier * 6) // Direct to the array.
Good luck
Chris Howie
13,216 PointsThank you so much that was a great explanation!