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

Randell Purington
Randell Purington
9,992 Points

Where am I getting my error from?

swift_lint.swift:10:10: error: expected '{' after 'if' condition if n 2 % 1 == && n % 7 == 0 { ^ swift_lint.swift:10:33: error: braced block of statements is an unused closure if n 2 % 1 == && n % 7 == 0 { ^ swift_lint.swift:10:8: error: 'Int' is not convertible to 'Bool' if n 2 % 1 == && n % 7 == 0 { ^ swift_lint.swift:10:33: error: expression resolves to an unused function if n 2 % 1 == && n % 7 == 0 {

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

for n in 1...100 {
    // Enter your code below
    if n 2 % 1 == && n % 7 == 0 {
      results.append(n)
    }

    // End code 
}

1 Answer

Hey Randell,

To check if an integer is even or odd, you’ll want to see if said integer is evenly divisible by two. So, if an integer is divided by two and leaves no remainder, then that integer is even.

The Challenge, though, wants to know which integers are odd. So, instead of if n % 2 == 0, you’d filter for the opposite: if n % 2 != 0.

Finally, don’t forget that the Challenge doesn’t just want odd numbers; it wants numbers that are cleanly divisible by 7.

You should probably be able to figure it out from here. Feel free to ask for clarification if you need it ;)