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

I cant get it right

I'm trying to solve this challenge but it was a little bit complicated for me due to the condition inside the loop, and im having issues with the logic operators, maybe a hint of what im doing wrong or how this kind of operations in an if condition can be done.

logicalOperators.swift
var results: [Int] = []
for n in 1...100 {
    // Enter your code below
  if n %7 = 0 && n % 3 = 0 {

    }

}

1 Answer

Manuel Pascual
Manuel Pascual
4,676 Points

Hi! You have to use == instead of =. Also have to change "n % 3 = 0" by "n % 2 != 0" to check if it's and odd number. The final result would look like this:

var results: [Int] = []
for n in 1...100 {

    if (n % 2 != 0) && (n % 7 == 0) {
        results.append(n)
    }

}

Try always to organize your conditions using parentheses. Hope this helps!