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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Justus Aberson](https://secure.gravatar.com/avatar/24fc526d23e29241454d6f1cc3bd0dbd?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Justus Aberson
1,035 PointsI dont understand what to do.
Hey guys, can someone please explain to me what to do? Thanks.
var results: [Int] = []
for n in 1...100 {
// Enter your code below
if
// End code
}
2 Answers
![Henrik Brüntrup](https://secure.gravatar.com/avatar/a8041a7af866284d7ee84e5108c54927?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Henrik Brüntrup
5,485 PointsHi Justus,
you need to use the && operator in the if statement and append the numbers that are both unequal and divisible by 7:
var results: [Int] = []
for n in 1...100 {
// Enter your code below
if (n % 2 == 1) && (n % 7 == 0) {
results.append(n)
}
// End code
}
Btw. it is good practice to mark an answer as 'best answer' in your threads, if a successful solution has been posted. It lets others know that the answer has been given and no longer needs to be looked at. I posted an answer to your earlier thread about while-loops and it never received feedback from you.
![Henrik Brüntrup](https://secure.gravatar.com/avatar/a8041a7af866284d7ee84e5108c54927?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Henrik Brüntrup
5,485 PointsSure.
Quoting Apple: The remainder operator (a % b) works out how many multiples of b will fit inside a and returns the value that is left over (known as the remainder).
So the line
if (n % 2 == 1) && (n % 7 == 0) {
means, that the remainder operator will work out how many 2s will fit inside 'n' and if the remainder is 1 and (&&) will then work out how many 7s will fit inside 'n' and if there is no remainder, if this is the case it will then
results.append(n)
append 'n' to the 'results' array.
For example 'n' = 14 will not be added to the array because 2 x 7 = 14 -> no remainder - 'n' = 21 will be added because 2 x 10 = 20 (remainder of 1 to 21) or 2 x 11 = 22 (remainder of 1 to 21) and 7 x 3 = 21 ( no remainder)
Justus Aberson
1,035 PointsJustus Aberson
1,035 PointsThanks, Henrik, but I dont understand your code, can you please explain?