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

Dustin Jones
seal-mask
.a{fill-rule:evenodd;}techdegree
Dustin Jones
iOS Development Techdegree Student 1,573 Points

Everything looks right, but I can not get a correct answer from this challenge. Please help.

What am I doing wrong and can you please explain?

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

for n is 1...100 {
    if (n % 2 != 0) && (n % 7 == 0) {
    results.append(n)
    }
}

4 Answers

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,858 Points

Hey Dustin,

Your code is correct; however, it looks like you altered a key word in the preloaded code, and that is what is throwing the error.

You changed in to is in the opening for loop. It should read for n in 1...100. Fix that up and you're good to go.

Keep Coding! :dizzy:

Sean Riley
Sean Riley
7,087 Points

You just have a typo in there, "for n is 1...100" should read "for n in 1...100", the rest of your code is exactly right.

Maybe this will work?

I'm not sure.

var results: [Int] = []

for n is 1...100 {
    if (!n) && (n % 7 == 0) {
        results.append(n)
    }
}
Jason Anders
Jason Anders
Treehouse Moderator 145,858 Points

Nope, that won't work. Spelling error in for loop and logic is incorrect in if statement.

Oops, didn't notice that XD