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

martijn van der wal
martijn van der wal
5,972 Points

i’m stuck here, i have copied this from someone in the comments but it doesn’t work anyone knows why?

i’m stuck here, I have copied this from someone in the comments but it doesn’t work anyone knows why?

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

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

        results.append(n)
    }
    // End code 
}

2 Answers

The only mistake you are making is that you are dividing it when we need to find the remainder using the remainder operator (%). Also don't forget to close the curly brace. Just fix in the code below

if (n % 2 != 0) && (n % 7 == 0) {
      results.append(n)
    }
Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! I'd be at least mildly interested to know where you copied this from. But here are a couple of things that are incorrect.

  • You're not using the modulus (%) operator, you're using the division (/) operator
  • You're supposed to be looking for n % 7 == 0, not 7 / 100 == 0

Your first condition will always evaluate to true. The only number divided by two that results in a zero is zero. For instance 3 / 2 = 1.5 and 1.5 is not equal to zero. The second condition will always evaluate to false. Seven divided by 100 will always be .07 . It will never be zero.

See if you can get it working with these hints. Let me know if you need more help! :sparkles: