Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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

Aramik YOUSEFZADEH
PLUS
Aramik YOUSEFZADEH
Courses Plus Student 895 Points

Code Error

I can not find my symtax problem.

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

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

    } else { n+=1 } 
    // End code 
}

Hello Aramik. I think I've found the syntax error. You have too many parentheses in the if conditional -

((n & 7 == 0) && (n % 2 != 0))

try this: (n & 7 == 0) && (n % 2 != 0)

Also, the [int] should have a capital I(case sensitive), so put [Int].

The third error is the append value statement. The parentheses must be directly after append without spaces. Make sure to add an s to result, so that it matches the variable called at the top. It should look something like this:

results.append(n)

As far as the n+=1 & else statement, the two are not necessary, but shouldn't cause an error if not removed.

Hope this was helpful.

2 Answers

Jeff McDivitt
Jeff McDivitt
23,970 Points
  1. There is no need for parentheses in Swift
  2. Add an s on result
  3. You do not need n += 1
var results: [Int] = []

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

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

    }

    // End code 
}