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

I dont get it...

Hey guys, the bummer is telling me that my multiplication needs to go from 1 to 10, i have got that code, 1...10 but its giving me a failure. Can anyone help me out?

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

}

1 Answer

Julien riera
Julien riera
14,665 Points

Hello,

It looks like you skipped over this part :

For in loops also define a constant that temporarily stores the value in the iteration process. For the loop you're writing, name this constant multiplier.

Also, your results variable is an empty array. Which means you can't loop through it as it contains no value.

You actually have to loop directly through your range. Here :

var results: [Int] = []
for multiplier in 1...10 {

}

That will validate you step 1. I will put my solution for the step 2 a few lines below, feel free to complete the challenge with the previous help before you read the following.

Hope this helps !

Cheers,

Julien

. . . . . . .

// Enter your code below
var results: [Int] = []
for multiplier in 1...10 {  // "multiplier" stores the value temporarely each time it gets through your loop, here a range from 1 to 10
  let x = multiplier * 6  // then, as the step 2 ask for it, you multiply the value stored from your range into "multiplier" by 6
  results.append(x)  // then, you store it in a box which allows you to keep or use it, the array names "results"
}

Or shorter :

// Enter your code below
var results: [Int] = []
for multiplier in 1...10 {
  results.append(multiplier * 6)
}
Jason Anders
Jason Anders
Treehouse Moderator 145,858 Points

Mod Edit: Changed response from Comment to an Answer