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 2.0 Collections and Control Flow Control Flow With Conditional Statements Working with Logical Operators

Hi, online editor doesn't work properly. it keep telling use of unresolved identifier 'results'

here is my answer: var results: [Int] = []

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

    results += [n]
    print(results)
}

// End code

} and this is error i get: swift_lint.swift:10:11: error: use of unresolved identifier 'results' print(results) in my xcode everything works just fine. i don't know why the online code editor keep generating same error despite changing the var names or removing the whole code. so i'm can't move on without solving this issue

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

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

    results += [n]
    print(results)
    }

    // End code 
}

2 Answers

Rzgar, try this:

var results: [Int] = []

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

    results.append(n)
    print(results)
  }
}

You are trying to add [n] to the array, but you need add only n, and you need to use the append() method. += worked in Swift 1.0, but it no longer works in Swift 2.0.

Thank you @jcorum .I managed to figure it out and edited the code exactly as you are suggesting here. Thank you again for taking time :)