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

Danny Kilkenny
Danny Kilkenny
4,507 Points

Unable to solve this code challenge in Swift Control flow

Can anyone maybe rephrase this question to make it a little more understandable? I can't figure out how to append the results of a for loop to an array

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


for results in 1...10 {
    let multiplier = results

    }
Danny Kilkenny
Danny Kilkenny
4,507 Points

var results: [Int] = []

for results in 1...10 { let multiplier = results

}

results.append(multiplier)

I did try this but I was met with an error

1 Answer

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

Hi there! You're using results in your for loop, but that's supposed to be multiplier. Let me see if I can rephrase what they want. I'm going to give you the beginning of the for loop though:

for multiplier in 1...10

Our results array is empty right now, correct? And what we want is to use the append method inside our for loop so that the results array will end up looking like this [6, 12, 18, 24, 30, 36, 42, 48, 54, 60]. And given that multiplier runs from 1 to 10 all we need to do is multiply the multiplier by 6 and append() that to the array. And it's very close to what you posted in your second bit of code except that it should happen inside the loop.

Give it another shot with these hints! :sparkles:

Danny Kilkenny
Danny Kilkenny
4,507 Points

Thank you! That helped me solve the problem