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

Website doesn't accept this.

I have programmed this and it is working fine in Xcode but the website doesn't accept this. What is it that I'm doing wrong here?

var results: [Int] = [] var multiple = 0

for n in 1...100 { if ((multiple % 2) != 0) && multiple == (n * 7) { results.append(multiple) } }

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

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

    // End code 
}

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! While this may run in Xcode without errors, your code is not producing the correct results. So I'm going to give a couple of hints here.

  • The multiple variable is not needed nor is the value ever changed in your code
  • The resulting array should look like this [7, 21, 35, 49, 63, 77, 91]

Hope this helps! :sparkles:

Hi Jennifer, Ok that sounds understandable, thank you for your reply. I saw after reading your comment that I didn't copy the complete code, there was a line with multiplying the multiple variable. I have completed the course with this code: if ((n % 7 == 0) && (n % 2 != 0)) { results.append(n) }

Thanks again for your help.

Kind regards, Mark Kik.