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

KRIS NIKOLAISEN
PRO
KRIS NIKOLAISEN
Pro Student 51,960 Points

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

Thank you!