iOS Swift Collections and Control Flow Control Flow With Conditional Statements Working With Logical Operators

Johnny Nguyen
Johnny Nguyen
3,180 Points

Why I get bummer? I get on Xcode and I can see that the array "results" is full of numbers that is odd and multiple of 7

Bummers while on Xcode it's right

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

for n in 1...100 {
    // Enter your code below
        if n / 7 != 0 && n % 7 == 0 {
            results += [n]
        }

    // End code
}

2 Answers

Steve Hunter
MOD
Steve Hunter
Treehouse Moderator 56,758 Points

Hi there,

Your tests aren't quite right. Testing n / 7 != 0 will always be true since n is never zero. You then test for n % 7 == 0 which isn't testing for oddness.

To see if n is a multiple of 7, test n % 7 == 0, then to test for oddness, see if n % 2 != 0. Combine those two in your if statement. If n passes, use the .append() method on results to add n to results.

I hope that helps.

Steve.

Johnny Nguyen
Johnny Nguyen
3,180 Points

Thank you so much. You got it correctly