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

Eliyah Kohein
Eliyah Kohein
20,283 Points

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: +=

Eliyah Kohein
Eliyah Kohein
20,283 Points

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 
}