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

Arthur Boilanger
Arthur Boilanger
3,372 Points

Unable to Append multiplier to results array

I'm having an issue with appending the value that my for-in loop "multiplier"

for multiplier in 1...10 {
    print("\(multiplier) times 6 is \((multiplier) * 6)")
}

to my results array for the 2nd challenge task.

I've tried using

results.append(multiplier)

but keep coming up with an error.

1 Answer

Hi Arthur,

You want to append results.append(multiplier * 6) as the array should hold, to quote the question, the array will contain the first 10 multiples of 6

I hope that helps.

Steve.

Arthur Boilanger
Arthur Boilanger
3,372 Points

Hi Steve,

I tried that and am now getting an error saying

swift_lint.swift:10:18: error: use of unresolved identifier 'multiplier'
  results.append(multiplier * 6)
                ^

Thanks for taking the time to help, I appreciate it!

Just checking that you've got that line in the right place. It needs to go inside the for loop:

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

THe name of the variable in the for loop needs to match the variable being multiplied and appended. The challenge wants that to be called multiplier. That code clears the challenge.

Steve.

Arthur Boilanger
Arthur Boilanger
3,372 Points

D'oh! I figured it out!

I was putting results.append outside of the loop, so it didn't know what multiplier was.

It should read as follows:

for multiplier in 1...10 {
    print("\(multiplier) times 6 is \((multiplier) * 6)")
    results.append(multiplier * 6)
}

Thank you again for the help Steve!

Spot on! Good work. :-)