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 Collections and Control Flow Control Flow With Loops For In Loops

James Austin
seal-mask
.a{fill-rule:evenodd;}techdegree
James Austin
iOS Development Techdegree Student 1,700 Points

adding multiples to results array from for in loop

I can't seem to understand what this is asking for. It wants the results to contain the first 10 multiples of 6

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

results.append(multiplier)}

2 Answers

Greg Kaleka
Greg Kaleka
39,021 Points

Hi James,

The challenge wants you to put the multiples of 6 into the array (not the multipliers). Multiples of 6 are things that are divisible by 6, so 6, 12, 18, 24, etc. A very small change to your code will fix this.

One other note - be careful of your code formatting. It doesn't matter to the compiler, but it's much easier to understand what's happening in this code:

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

This will become more and more important as your code becomes more complex. It's a good habit to get into now.

Cheers :beers:

-Greg

James Austin
seal-mask
.a{fill-rule:evenodd;}techdegree
James Austin
iOS Development Techdegree Student 1,700 Points

I ended up just modify the append statement results.append(multiplier * 6)

This worked out. I do see where it’s easier to read that formatting, will work on dis.

Greg Kaleka
Greg Kaleka
39,021 Points

Perfect - nice work!