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 trialJorge Castillo
820 PointsWhat's wrong with this code please?
This code is working on Xcode, why not at tester
var results: [Int] = []
for n in 1...100 {
// Enter your code below
var value2 = n % 2
var value7 = n % 7
if value2 == 0 && value7 == 0 {
results.append(n)
}
// End code
}
4 Answers
Ethan Neff
27,058 Pointsyour spacing is incorrect.
change value2! = 0 to value2 != 0
the below solution works
var results: [Int] = []
for n in 1...100 {
// Enter your code below
var value2 = n % 2
var value7 = n % 7
if value2 != 0 && value7 == 0 {
results.append(n)
}
// End code
}
Ethan Neff
27,058 Pointsyou're checking for even and not odd.
try this value2 != 0 instead
Jorge Castillo
820 PointsThanks, Ethan. We are trying to find how many numbers from 1 to 100 are odds and multiple of 7.
value2! = 0 won't work it out.
Thanks, again
Jorge Castillo
820 PointsThanks, you helped me a lot of. Now I can move forward.
So long, thanks, again
Jorge