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

Confused on multiple of 7, append the value to the results array provided.

would it be if n !even && multipleof7 ....

I am not sure how I spend the value to the results array provided? what does that mean exactly?

Do I need to do more code to find the multiples of 7?

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

for n in 1...100 {
    // Enter your code below
    if n !even && multipleof7 {
    print("7")
    }
    // End code 
}

2 Answers

Ghareisa Al-Kuwari
Ghareisa Al-Kuwari
1,465 Points

The question requires 3 main things, to find if the number is not even then to find if the number is a multiple of 7, lastly if both conditions are true we append the number to an array named results. Let's take that a bit by bit

1. If the number is not even: Using the remainder operator % we can find out if a number is even or odd by dividing it by 2, meaning if a number is even, when divided by 2 there will be no remainder, if it is odd there will be a remainder. So the not even part should be

 !(n%2==0)

If the remainder of n divided by 2 is 0 then the number is even, but the question requires the number to be not even, so we add the not operator

2. If the number is a multiple of 7: Technically, a number that is a multiple of 7 should have zero remainder when divided by 7. So Taking the module operator %, if n is a multiple of 7 then remainder is 0.

n%7==0

3. Appending: Append the value as in add that value to the array and it is done by the append method, which always adds the element at the end of the array, so the solution overall is going to be

if( !(n%2==0) && n%7==0 ) {
   results.append(n)
}

thANKS!