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

Ivan Cadena
Ivan Cadena
2,949 Points

help with If statements

Im not sure what I'm doing wrong here, it keeps saying that its wrong. Can someone please explain?

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

for n in 1...100  { if  n % 2 == 1 && n & * 7 == 0 { results.append(n)

}

4 Answers

Grant Thomas
Grant Thomas
13,705 Points

Cleaning it up.

  1. It looks like you were missing a '}'
  2. I wrapped the expressions between your && operator
  3. changed the '& *' to '%'
var results: [Int] = []

for n in 1...100 {
  if  (n%2 == 1) && (n%7 == 0) {
  results.append(n)
    }
}
Zachary Kaufman
Zachary Kaufman
1,463 Points

After the && n there's a & that doesn't belong there. Try deleting that.

Ivan Cadena
Ivan Cadena
2,949 Points

it still says its wrong :(

Zachary Kaufman
Zachary Kaufman
1,463 Points

Would you mind telling me the error it gives you?

Ivan Cadena
Ivan Cadena
2,949 Points

Bummer! Make sure you are performing logical checks in the condition of the if statement

Zachary Kaufman
Zachary Kaufman
1,463 Points

Oops I think I see the problem. You have if n * 7 == 0 it needs to be if n %7 ==0 and also delete the & after n. I think this will get it to work.