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

fort ciprian
fort ciprian
1,234 Points

I'm stuck

I dont know what its wrong

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

2 Answers

Let's go one step at a time.

We start with the results array, which is empty:

var results: [Int] = []

You then created the loop, using multiplier as the loop variable:

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

}

Now, we want to append something into the results array. We use dot notation to add items into an array. Something like:

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

What we want to append into the array is the value of multiplier multiplied by 6. That gives us:

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

I hope that explains it fully for you.

Steve.

No problem! :+1:

Hi there,

You don't need to put a string together. The question says Once you have a value, append it to the results array.

You want to use the loop variable, multiplier, and multiply it by 6. Use the append() method on the results array (use dot notation) to add multiplier * 6 to the array.

I hope that makes sense.

Steve.

fort ciprian
fort ciprian
1,234 Points

i still don't get it. I'm confused rigt now.

fort ciprian
fort ciprian
1,234 Points

I thing I want to do the task in a more complicated way.. and the task is much easier