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 trialDiego Aguirre
13,211 PointsLooping over Ranges code challenge: I can't seem to get the results array to contain the new looped array
var results: [Int] = []
for multiplier in 1...10{
print("\(multiplier) times six is equls to \(multiplier * 6)" )
results = [multiplier]
}
In Xcode the loop area seems to be working fine but when I call results outside of the loop I seem to get the following answer [0]10 . I have a feeling it's a silly scope issue i'm having here
2 Answers
Steve Hunter
57,712 PointsHi Diego,
Your loop looks fine - the issue is with creating the array.
What you want to do is multiply multiplier
by 6 and append that value into the results
array. At the end of the loop, results
will hold [6, 12, 18, 24 ... etc ]. There's no string to output.
Try with something like this:
var results: [Int] = []
for multiplier in 1...10{
results.append(multiplier * 6)
}
I hope that helps,
Steve.
Diego Aguirre
13,211 PointsThanks Steve! Totally forgot about the append feature