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

Tony Gross
Tony Gross
1,267 Points

Where am I going wrong ? I am trying to store results of for loop into an array

I'm getting an error message saying " Make sure the results array contains the first 10 multiples of 6"

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

for multiplier in 1...10 {


print("the multiple is \( multiplier ) times 6, which is equal to \( multiplier * 6)")
results.append(  multiplier )
}

1 Answer

Aniruddha Shukla
Aniruddha Shukla
2,846 Points

You are not appending the results array with the right result.

var results: [Int] = [0]

for multiplier in 1...10 {
results.append(  multiplier * 6 )
}
Tony Gross
Tony Gross
1,267 Points

var results: [Int] = [0]

for multiplier in 1...10 {

print(" The multiple is (multiplier) times 6, which is equal to (multiplier * 6)")

results.append( multiplier * 6 )

}

/* I changed what I am appending to "multiplier * 6 " but I am still getting the same error message */