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

Jonathan Holland
seal-mask
.a{fill-rule:evenodd;}techdegree
Jonathan Holland
iOS Development Techdegree Student 4,037 Points

This challenge has really stumped me. I can't figure out how to check to see if the number is not even and attach result

i tried: "if n %2 != 0 && n / 7 { results = n }, but it gives error saying that i can't use "&&" with a BOOL and INT. and apparently i'm not attaching results properly to array.

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

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

    // End code 
}

2 Answers

Instead of n/7 you should use n % 7 == 0 to find if the number is divisible by 7 and also where you have result = n you should say result.append(n) ex

if n % 2 != 0 && n % 7 == 0 {
  results.append(n)
}
Jonathan Holland
seal-mask
.a{fill-rule:evenodd;}techdegree
Jonathan Holland
iOS Development Techdegree Student 4,037 Points

thanks! was this covered in the TechDegree? Because I don't remember anything with "%" and using it to check if something is divisible or not-equal to something..

The symbol (%) is known as the modulus operator, or mod for short. It has the same functionality as the modulus operator in basic math. I'm not sure if it was been taught in the TechDegree program but there are many resources on it online

Curtis Bridges
Curtis Bridges
17,720 Points

You can check for a remainder rather than using outright division:

    if n % 2 != 0 && n % 7 == 0 {
        // n is not even and is divisible by 7
    }

In this case, both sides of the condition are booleans.