Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

What do you do when your code executes perfectly on the online Swift playground but does not pass "Recheck Work" ?

The following code works on the online Swift playground, but does not pass the test when I "Recheck work". I added the print(results) statement to verify that it works...

var results: [Int] = []

for n in 1...100 { // Enter your code below // n % 2 returning a zero indicates an even number, so have to use NOT operator let even = n % 2 let sevensMultiple = n % 7 if !(even == 0) && (sevensMultiple == 0) { // add number to the array results += [n] print(results) } }

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

for n in 1...100 {
    // Enter your code below
    // n % 2 returning a zero indicates an even number, so have to use NOT operator
    let even = n % 2
    let sevensMultiple = n % 7
    if !(even == 0) && (sevensMultiple == 0) {
          //   add number to the array
          results += [n]
    }
}

2 Answers

In reviewing students previous posts it looks like the checker wants you to use the results.append() method. Good job though.

Thank you!