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 trialSam Brown
1,908 PointsCode works in Xcode, but gives me an error in browser/tutorial..
It looks like the tutorial is having trouble with 'n', but other than that I have no clue where to start.
var results: [Int] = []
for n in 1...100 {
// Enter your code below
if (n % 2 == 1) && (n % 7 == 0) {
results += [n]
}
// End code
}
1 Answer
andren
28,558 PointsThe issue is that the code checker for this task is quite picky. It expects you to use the append
method to add numbers to the array rather than using concatenation like you are doing.
The resulting array will be the same either way, but unless the code checker sees the append
method being used it won't pass the code.
Here is your solution modified so it will pass the challenge:
var results: [Int] = []
for n in 1...100 {
// Enter your code below
if (n % 2 == 1) && (n % 7 == 0) {
results.append(n)
}
// End code
}
Sam Brown
1,908 PointsSam Brown
1,908 PointsAh I see. Thank you!