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

Not sure how to get the equation results too append into the "results" array.

Is the loop body even correct?

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

for multiplier in 1...10 {
  print("\(multiplier) times 6 is equal to \(multiplier * 6)")
}

results.append(multiplier)

1 Answer

Michael Hulet
MOD
Michael Hulet
Treehouse Moderator 47,826 Points

You have all the right building blocks here to pass the challenge, though they're not all in the right place. First of all, this challenge doesn't require you to print anything. All you need to do is append to the results array. You've already written some good code to do that, but it's outside the loop (the multiplier constant is only valid within the loop, and not outside). That being said, don't forget to multiply your multiplier by 6 before you append it (which is something you've done correctly at the end of the print you have)!

Once you combine those couple things, you should be good to go