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

Ricardo Gonzalez
Ricardo Gonzalez
2,286 Points

How do I add the for in loop to the variable results?

Don't know how to finish challenge.

loops.swift
var results: [Int] = []
for multiplier in 1...10 {
print("\(multiplier) times 6 is equal to \(multiplier * 6)")
}

1 Answer

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

You've set up your for loop just fine! However, the challenge doesn't ask you to print anything. They want you to take multiplier and multiply it by 6 then put that into the results array. So the end result array will contain 6, 12, 18, 24, 30, 36, 42, 48, 54, 60. Here's how I did it:

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

They set up the results array for you. Your job is simply to take the result of 6 * multiplier and put it in the array. Hope this helps!