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

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
Michael Hulet
47,912 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