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 trialDenny Louis
10,885 PointsAm I doing something wrong?
I'm getting a message when I submit my code saying "Make sure you're appending the correct values to the results array in order to pass the challenge".
I've tested my code in a Swift Playground and it doesn't say I have any errors and the results array has all of the values inside, not sure what I am doing wrong?
var results: [Int] = []
for n in 1...100 {
// Enter your code below
if n % 2 != 0 && n % 7 == 0 {
results += [n]
}
// End code
}
3 Answers
Jason Anders
Treehouse Moderator 145,860 PointsHey Denny,
The loop will return a single Integer every time it iterates through itself, so nstead of using the unary operator +=
to add what would need to be another array to the results array, try using the .append
method. :)
Keep Coding!
Pasan Premaratne
Treehouse TeacherIndeed it is the solution checker ensuring that you use append here. I'll update this to include concatenation
John Wilcox
4,233 PointsHi, I'm having the same issue today. Could the simulator still be updated to include concatenation, or could the question be updated to steer the user away from concatenation?
Pasan Premaratne
Treehouse TeacherHey John,
Could you post what error you're specifically getting when you use concatenation. It should work but I might be missing a particular variation
Denny Louis
10,885 PointsDenny Louis
10,885 PointsHey Jason, thank you for your answer, the append method worked.
Are you able to explain why the append method worked, but concatenation wasn't accepted? I'd just like to know so I don't make the mistake again. It's pretty confusing since it worked for me in Xcode.
Thanks!
Jason Anders
Treehouse Moderator 145,860 PointsJason Anders
Treehouse Moderator 145,860 PointsHey Denny,
It does work in Xcode's playground, and as far as I can tell, it's valid syntax and produces the same result.
In this instance, however,I think it's probably just the code checker for the challenge being picky and particular to a certain way (here the
.append
method).But I would like Pasan Premaratne to just confirm please. :)