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 trialSan Francisco
28,373 PointsSwift 2.0 Collections and Controllers Challenge Task 1 of 2
In the challenge task here:
Can someone please provide a working example thanks
// Enter your code below
var results: [Int] = []
let multiplier = number
for number in 1...10{
print("\(number) times 5 is equal to \(number * 5)")
}
1 Answer
Farhad Mohammad Afzali
5,007 PointsHi, There are 2 problems in your code:
- You are assigning "number" to multiplier, which is not possible because the number variable is working only inside loop scope. Also, assigning an iterating value to a constant is not possible.
- You should add the resulted value to the array instead of printing it.
Below is my solution.
var results: [Int] = []
let multiplier = 6
for number in 1...10 {
results.append(number * multiplier)
}
San Francisco
28,373 PointsSan Francisco
28,373 PointsThanks Farhad!
Farhad Mohammad Afzali
5,007 PointsFarhad Mohammad Afzali
5,007 PointsYou are welcome