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

Andrew Martinez
Andrew Martinez
3,337 Points

Objective 2 Help

Inside the body of the loop, we're going to use the multiplier to get the multiple of 6. For example, if the multiplier is 1, then the multiple is 1 times 6, which is equal to 6.

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.

var results: [Int] = []

for multiplier in results { print("(1...10) time 6 is equal to (1...10 * 6)") }

THIS IS WHAT I WROTE FOR THE SECOND OBJECTIVE:

results.append(multiplier)

i don't really know what to write in there.

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


for multiplier in results { 
     print("\(1...10) time 6 is equal to \(1...10 * 6)") 
     }

3 Answers

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

Hi Andrew Martinez! You're on the right track! I see you used append. But your for loop is set up as a range of for multiplier in results. First, this will never run. That's because results is an empty array. It wants us to fill up that array with... you guessed it... results!

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

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

So here we start with the results array they give us. Now we're going to go through the range 1 to 10 as specified by the challenge. Every time through we're going to append the multiplier times 6. Our results array should end up looking like this: [6, 12, 18, 24, 30, 36, 42, 48, 54, 60]. I hope this helps! :sparkles:

Cindy Lea
PLUS
Cindy Lea
Courses Plus Student 6,497 Points

They are looking for something like this: for multiplier in 1...10 { results.append(multiplier * 6) }

Andrew Martinez
Andrew Martinez
3,337 Points

Thanks Jennifer Nordell and Cindy Lea for the help! I really appreciate it.