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

Bryce Patrick
Bryce Patrick
10,099 Points

I cannot get past this question. My range is set to 1...10 which should be retrieving the first 10 multiples of 6.

What do i need to fix in my code to get to the next step? Help :)

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

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

1 Answer

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hey Bryce. Welcome to Treehouse.

For the first part of the challenge, you are only asked to create the for in loop. You added a print statement that was not asked for. Challenges are very strict. Often if you add more than what was asked, modify preloaded code, etc... you will get the "Bummer..."

So, all you need for Task 1 is

var results: [Int] = []

for multiplier in 1...10 {

}
Bryce Patrick
Bryce Patrick
10,099 Points

Hey Jason,

Thank you for your response. I can get past task one but i cannot get past the second task. It keeps telling me that my range is off? Any ideas of how to pass this challenge? I've been stuck for quite some time lol.

Sincerely,

Jason Anders
Jason Anders
Treehouse Moderator 145,860 Points

For the second task, you only need to add one line of code inside the for loop. The challenge wants you to append the value of 6 multiplied by each multiplier. With each iteration of the loop, the multiplier will be different and we want to add to the results array. This is done with .append()

var results: [Int] = []

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

I would suggest, maybe, review the previous videos before moving on, because the loops get more complex and will move to switches and functions. Without a complete understanding of these past few videos, the next section will be very difficult. I often review and rewatch before moving on.

:)