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

HI I am not sure how to do this question

Pls teach me

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

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

   }

    // End code 
}

1 Answer

This project had two parts, so let us break down each one.

The first part was making getting the odd numbers out of the range. You are using the correct operand, just need to look at the order of it. From Apple Developer documentation:

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 to find an even number we need to take that number and make sure we have a remainder of 0, to find an odd number we have a remainder value that is not 0. This would look something like

n % 2 != 0 or n % 2 == 1

The next part is the multiple of 7. I was able to find this using the same process as finding the odd numbers. If the number n divided by 7 == 0 then it should be a multiple of 7. That would look like this

n % 7 == 0

Then just put them both together like you did above.

if n % 0 != 0 && n % 7 == 0 { // append to array here }

I hope that helps you. :D

Thank you so much