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 trialzerodays
5,257 Pointstask 2 of challenge
what exactly am I doing wrong for returning the values for task 2?
// Enter your code below
var results: [Int] = []
for multiplier in 1...10 {
var multiplier = "\(multiplier) * \(6)"
results += [multiplier]
}
Additionally, could someone please explain how this code will also passes the first task??
// Enter your code below
var results: [Int] = []
for multiplier in 1...10 {
var multiplier = ("\(results) * \(6)")
}
2 Answers
zerodays
5,257 PointsThanks for the feedback! Your method also works! However, I ended up solving the issue with my own code; the issue was due to syntax error, it was misinterpreting multiplier as a string instead of an int, so I was running into issues appending that into results... Here is the working code:
// Enter your code below
var results: [Int] = []
for multiplier in 1...10 {
var multiplier: Int = multiplier * 6
results.append(multiplier)
}
and in retrospect--after viewing other forum posts--refactored and clean simplified code with less complexity would be:
// Enter your code below
var results: [Int] = []
for multiplier in 1...10 {
results.append(multiplier * 6)
}
alexand
5,057 Pointsvar results: [Int] = [] let multiplier = 6 for number in 1...10 { results.append(multiplier * number)}
alexand
5,057 Pointsalexand
5,057 Pointsthis is as far as I got var results: [Int] = [] for multiplier in 1...10 { print("(multiplier * 6)")}
don't know how to append the value of the results....