Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Swift 2.0 Collections and Control Flow Control Flow With Loops For In Loops

do not understand task to on collections and control flow code challenge

For task two, I do not understand what it is asking me to do. In the first task it asks to make the multiplication table for the number 6 which I did,

for multiplier in 1...10 { print (multiplier * 6) }

But can someone explain what the second task is asking.

// Enter your code below
var results: [Int] = []
for multiplier in 1...10 {
print (multiplier * 6)

2 Answers

Jennifer Nordell
Jennifer Nordell
Treehouse Teacher

You're so close here! You've got everything set up correctly, but instead of putting the result of the multiplier * 6 in the results array... you're just printing it out. What we want is the results array to start off empty but end up looking like this: [6, 12, 18, 24, 30, 36, 42, 48, 54, 60]. So the only line you really need that's different from what you currently have is this:

results.append(multiplier * 6)

Hope this helps! :sparkles:

Hi Jennifer,

Thank you for your help. I also noticed when I went back to step one, that all they really were looking for on the first task was to set up the range part of :

for multiplier in 1...10{ }

So when I got to the second task and had already had it set up from step one doing the multiplication I was totally confused why they were still asking about calculating the multiples of 6.

Second mistake I made was thinking that you could use the printed results as the numbers in the array. I was playing around in Xcode as such:

var results: [Int] = [for multiplier in 1...10 { print (multiplier * 6) } ]

I thought by doing the above it would print the integers into the array, I soon found that didn't work. From there I then thought to use the append method similarly as:

results.append( for multiplier in 1...10 { print (multiplier * 6)}) thinking I could append the outcome of the print method into the array.

Thank you again for the help, I just thought for some strange reason I had to use the print as in the examples in the video to complete the challenge. Never occurred just to use the append method in the body of the loop. Thank you, I can move on with my day now.