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 Collections and Control Flow Control Flow With Loops For In Loops

Jihong Min
Jihong Min
2,156 Points

Almost done but stuck... please help!

The complier keeps giving me this msg and I don't know what to do from here. " Make sure the results array contains the first 10 multiples of 6"

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

for multiplier in 1...10 { 
   results = [multiplier * 6]
} 

1 Answer

Rogier Nitschelm
Rogier Nitschelm
iOS Development Techdegree Student 5,461 Points

You are currently reassigning the results variable in every iteration. This means that the result will be:

[6] // first iteration
[12] // second iteration
[18] // third iteration
# ...
[60] // and eventually

This means the result will be [60] (the last assignment inside the loop).

Instead of trying to reassign the results-variable in every iteration, you want to add an element to it in every iteration. See if you can use the .append method to do this. Instead of results = [...]