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

What's wrong with this code please?

This code is working on Xcode, why not at tester

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

for n in 1...100 {
    // Enter your code below
    var value2 = n % 2
    var value7 = n % 7

    if value2 == 0 && value7 == 0 {
        results.append(n)
        }
    // End code 
}

4 Answers

Ethan Neff
Ethan Neff
27,058 Points

your spacing is incorrect.

change value2! = 0 to value2 != 0

the below solution works

var results: [Int] = []

for n in 1...100 {
    // Enter your code below
    var value2 = n % 2
    var value7 = n % 7

    if value2 != 0 && value7 == 0 {
        results.append(n)
        }
    // End code 
}
Ethan Neff
Ethan Neff
27,058 Points

you're checking for even and not odd.

try this value2 != 0 instead

Thanks, Ethan. We are trying to find how many numbers from 1 to 100 are odds and multiple of 7.

value2! = 0 won't work it out.

Thanks, again

Thanks, you helped me a lot of. Now I can move forward.

So long, thanks, again

Jorge