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 Collections and Control Flow Control Flow With Conditional Statements Working With Logical Operators

Dean Kreseski
Dean Kreseski
2,418 Points

Anybody can help on this one, still not sure about the wording of the question.

I understand the if statements and the operators I think its putting it all together. And also what is a good use for this in a app?

operators.swift
var results: [Int] = [0, 7, 21, 35, 49, 63, 77, 91,] 

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

 if (n % 7 == 0 && 5 & 2 != 0)

    // End code 
}
Nathan F.
Nathan F.
30,773 Points

It looks like you solved the problem, but to answer your second question--what use does this have for apps--this is a very common programming puzzle often called "FizzBuzz." Chances are if you interview for an app developer job, you might end up having to solve this problem.

Realistically speaking, you might use some code like this so that every other table view cell is a different color, or something like that. A problem like this is a good way of simply learning Swift syntax, like loops, equality checking, conditionals, comparators, etc.

3 Answers

Well, the challenge is asking you to append n to results only if n is divisible by 7 and an odd number. And anyway, the code that you tried isn't even correct. Your code should look like this actually:

var results: [Int] = []

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

Hope this helped! :-D

Dean Kreseski
Dean Kreseski
2,418 Points

I actually got it figured out right after I posted this. but thanks for your help.

Got it, just ask anyway!

Latrell Garnett
Latrell Garnett
2,840 Points

Hi,

I'm not understanding this one. I don't understand the operators logic in the if line of code (n % 7 == 0 && n % 2 != 0) how does it check for odd numbers?

well the part that says n%2 != 0, then that means n is not divisible by two. And only odd numbers aren't divisible by 2. so I guess that's your answer