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

if Statement

this particular question is not clear for me

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

for n in 1...100 {
    // Enter your code below
if n 
    // End code 
}

1 Answer

Tobias Helmrich
Tobias Helmrich
31,603 Points

Hey there Kevin,

to solve this challenge you have to check if n is odd and if it's a multiple of 7. If that's the case you have to append it to the results array. You can do that via the append method on the results array.

To check if n is odd you can use the inequality operator (!=) to see if the remainder of n divided by 2 is not 0. You can get the remainder of a division with the modulo operator (%). If that's the case, the number is odd.

To check if it's a multiple of 7 you also use the modulo operator and see if it is equal to 0. If so, it is a multiple of 7.

Also don't forget to connect the two comparisons with the logical operator &&.

It should look like this:

var results: [Int] = []

for n in 1...100 {
    // Enter your code below
    if n % 2 != 0 && n % 7 == 0 {
      results.append(n)
    }
    // End code 
}

I hope that helps, if you have further questions feel free to ask! :)