Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Swift 2.0 Collections and Control Flow Control Flow With Loops For In Loops

Vidura Rajapaksa
Vidura Rajapaksa
4,512 Points

Just can't figure out what I'm supposed to do

Re-watched the lessons over and over just can't figure out how to append the loop into the array...

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

for multiplier in 1...10 {
print ("\(multiplier) times 6 is equal to \(multiplier*6)")
}
Manuel Aurora
Manuel Aurora
Courses Plus Student 6,338 Points

Hi! You must APPEND result into the array. Like this:

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

2 Answers

Tobias Helmrich
Tobias Helmrich
31,601 Points

Hey Vidura,

good job until here! You almost got it right but the second task of the challenge wants you to append the multiples of 6 to the results array. You can do that by using the append method on the results array like so:

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

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

I hope that helps, good luck! :)

Vidura Rajapaksa
Vidura Rajapaksa
4,512 Points

Thanks guys the advice helped heaps! Was trying to tackle the problem from the wrong direction the whole time.

Cheers!