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 trial

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

Razvan L
Razvan L
463 Points

Challenge Task 2 of 2 - Swift 2.0 Collections and Control Flow

I'm stuck at figuring how to append the multiplier values to the variable "results". Within the loop, I need to figure out a way to have the machine give me the multiples of 6. How should I do that? And again, how to append the initial variable?

Thanks!

loops.swift
// Enter your code below
var results: [Int] = []

for multiplier in 1...10 { 

print("\(multiplier) times 6 is equal to \(multiplier * 6)")

}

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, Razvan L !

Well so far your for loop is set up. But you don't need the print statement. They've set up an empty array named results for you. What we're going to do is start at 1 and count to 10. We take the 1 and multiply it by 6 and get a result of 6. That six goes into our results array. And then 2 times 6. The end array would look like this: [6, 12, 18, 24, 30, 36, 42, 48, 54, 60]. And we do this with the append method. Take a look at my code and see if you can make it line up with my explanation:

// Enter your code below
var results: [Int] = []

for multiplier in 1...10 { 
  results.append(multiplier * 6);
}

Hope this helps! :smiley:

yes jen, tis does help although I'm going to have to refresh the video cause i'm not sure how we got here or where this was explained as a "method"?

Razvan L
Razvan L
463 Points

Thank you, I appreciate it!