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

what is the wrong here

// Enter your code below var results: [Int] = [] for multiplier in 1...10{

results[multiplier-1] = (multiplier * 6) }

loops.swift
// Enter your code below
var results: [Int] = []
for multiplier in 1...10{

results[multiplier-1] = (multiplier * 6)
}

2 Answers

Close!

var results: [Int] = []
var multiplier = 6;
for i in 1...10 {
  results.append(i * 6)
}

You need to create the multiplier variable outside the loop and give it a value, and then use it in the loop. You also need a loop counter (the i in the code above).

thanks a lot

thanks

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

I think your code might actually work. But it's not what they're looking for. They want you to use the .append function. Try this out:

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

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

thanks a lot

Jennifer's right, the code works, but not in the challenge. The editor won't accept it. I tried. When it says

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

you won't get past Task 1 unless there's a multiplier declared. It's interesting, but I just noticed that in the code I sent you multiplier is a var not a let, so the editor should have rejected my code as well!