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

Roy Reuveni
Roy Reuveni
2,621 Points

Hey there, I'm trying to figure out how to write the right condition to check if a number is both odd and a 7 multiple

Im using this condition in the Collections and Control Flow's task:

if n % 2 ==0 && n % 7 == 0 { }

What's not working here? Thanks! Roy

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

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

3 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! Oh wow you're close. In fact, if I change one single character it passes. And I'll give you a hint. I change an equal sign to an exclamation remark. Remember, if a number % 2 is equal to 0 it is even... not odd :smiley:

Give it another go with these hints in mind! :sparkles:

Roy Reuveni
Roy Reuveni
2,621 Points

Ahhh! Can't believe I missed that, you're so right!

  • Changed the first equal sign to an exclamation remark as you suggested. #success Thank you Jennifer!

As it says use not operator i.e !(n%2 == 0) for n in 1...100 { // Enter your code below if !(n % 2 == 0) && (n % 7 == 0){ results.append(n) } else{ print("not even") }

}