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 trial

iOS Swift 2.0 Collections and Control Flow Control Flow With Conditional Statements Working with Logical Operators

Paul Je
Paul Je
4,435 Points

Don't know what I did wrong!

Not sure which part is wrong - every bit makes sense on my own end lol. Any help would be sincerely appreciated

var results: [Int] = []

for n in 1...100 {
    // Enter your code below
    if n % 3 = 0 && n % 7 = 0 

1 Answer

Hi Paul,

I think we've covered this in a couple of other posts, but to clarify, the explanation is in this post; do let me know if you're still having problems.

I don't understand the 'comparison to 3' mod thing; I have to confess. I don't understand what 3 has to do with odd or even checking. As in my other post, 7 % 3 does not equal zero but 7 is odd; 9 % 3 is equal to zero, but 9 is odd.

So, that aside, you want to check for zero remainders using the % operator using not-2 (i.e. is odd) and 7. That means the number is divisible by not-2 and/or 7. The output of both those operations needs to be equal:

n % 2 != 0 && n % 7 == 0

Make sense?