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

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,603 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!