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

Tyler Dotson
PLUS
Tyler Dotson
Courses Plus Student 1,740 Points

array contains the first 10 multiples of 6

i need help with the code

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

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

2 Answers

Dan Lindsay
Dan Lindsay
39,611 Points

Hey Tyler,

While you definitely have a for in loop that is printing out the correct values for the multiples of 6 from 1 to 10, that’s not what the challenge is asking for. It is asking you to put those values in the results array. Just change the body of the loop to this:

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

and you will pass the challenge.

Tyler Dotson
Tyler Dotson
Courses Plus Student 1,740 Points

thank you so much I was able to figure it out with another way but your code makes a lot more sense I will be sure to use this way from now on. Again thank you !!!

Jeff McDivitt
Jeff McDivitt
23,970 Points
var results: [Int] = []

for multiplier in 1...10 {

results.append(multiplier * 6)


}