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

Temporary constant inside the loop named wrong?

Hey, it says the name of temp const is wrong. I seriously have no idea what's really the case, but it's not the name for sure.

Thanks in advance

loops.swift
// Enter your code below
var results = [1...10]

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

4 Answers

Kourosh Raeen
Kourosh Raeen
23,733 Points

Don't change the original empty array. Try this:

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

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

You are close

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


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

Thanks both of you! It worked but I still don't understand why the results array has to be empty.

Kourosh Raeen
Kourosh Raeen
23,733 Points

You want the results array to contain the first 10 multiples of 6, so we need to start we an empty array and using the loop add those multiples to the array. The first iteration of the loop adds 1 * 6, which is 6, to the array. Then next iterations adds 2 * 6, which is 12, to the array. The last iteration of the loop adds 10 * 6, which is 60, to the array and now you have: [6, 12, 18, 24, 30, 36, 42, 48, 54, 60]

If you start with an array that is not empty then it would not look like that when you are done.

Reed Carson
Reed Carson
8,306 Points

any time you change specific values the challenge has given you it will be wrong. It may be workable code but part of the course is following specific instructions and paying attention to details - very important for coding.