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 trialMatej Sindelar
5,286 PointsPlease help, cant get through this challange.
Anyone, can you please explain the logic after doing this corretly? :) Thanks!
var results: [Int] = []
for n in 1...100 {
if (n % 3 && n % 7 == 0) {
results.append(n);
}
}
1 Answer
Marina Alenskaja
9,320 PointsHi Matej
The problem is that you should compare each part of the conditions to 0 :
var results: [Int] = []
for n in 1...100 {
if (n % 3 == 0) && (n % 7 == 0) { /*The first parentheses checks
"if we divide this number, do we get 0?".
If that is true, if checks the second parentheses:
"If this number is then divided by 7, is it also 0?".*/
results.append(n);
}
}
Matej Sindelar
5,286 PointsMatej Sindelar
5,286 PointsThanks a lot! Now I get it! :)
Matej Sindelar
5,286 PointsMatej Sindelar
5,286 PointsAnyway, now Ive tried to put this into the challange, and it sais " Double check your logical conditions to ensure that the value being appended is both odd and a multiple of 7"
what should I do?
Marina Alenskaja
9,320 PointsMarina Alenskaja
9,320 PointsHmm that's weird.. I actually passed it by using n % 2 != 0 But I don't know how that's different.. Seems the same to me, but then again I suck at math! :-D