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 trialKurt Lyell
2,892 PointsChallenge 2 of 2, Collections and Control Flow
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.
I am not sure what is meant by append it to the results array. I really wish there was a hint section or something.
// Enter your code below
var results: [Int] = []
for multiplier in 1...10 {
multiplier * 6
}
1 Answer
Martin Wildfeuer
Courses Plus Student 11,071 PointsWhat you want to end up with is an Array containing the results of the multiplications. You can append elements to an array via append(newElement: Element)
which is a method you can call on arrays.
var results: [Int] = []
for multiplier in 1...10 {
results.append(multiplier * 6)
}
After the for loop, your results
array contains the result of every single multiplication.
There are other ways to do this as well, so I suggest reading through the Apple Swift Docs - Arrays
Hope that helps :)