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

Matej Sindelar
Matej Sindelar
5,286 Points

Please help, cant get through this challange.

Anyone, can you please explain the logic after doing this corretly? :) Thanks!

logicalOperators.swift
var results: [Int] = []

for n in 1...100 {
    if (n % 3 && n % 7 == 0) {
        results.append(n);
    }
}

1 Answer

Marina Alenskaja
Marina Alenskaja
9,320 Points

Hi 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
Matej Sindelar
5,286 Points

Thanks a lot! Now I get it! :)

Matej Sindelar
Matej Sindelar
5,286 Points

Anyway, 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
Marina Alenskaja
9,320 Points

Hmm 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