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

This should pass but it doesn't

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

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

You’re almost there. Try appending the result to the results array using: results.append(n)

Note: I believe that the method you were trying to use to append results used to work with older versions of Swift - but it has since been depreciated.

Addendum: as noted by Eliyah - it seems I may be mistaken about the depreciation of the additional assignment operator: +=

Well that definitely worked thank you though += hasn't been deprecated it was ++ and --. They even use it in the examples in the course, I really just think someone forgot to add the proper check when they wrote this code challenge.

1 Answer

var results: [Int] = []

for n in 1...100 {
    // Enter your code below

  if (n % 2 != 0) && (n % 7 == 0) {
    results.append(n)

  }

    // End code 
}