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

Michael Cafin
seal-mask
.a{fill-rule:evenodd;}techdegree
Michael Cafin
iOS Development Techdegree Student 1,221 Points

Request for subtle hint

As am I understanding what they are asking, I am having trouble what types are needed on how to find the "odd" numbers and on how to find the multiple of 7s by using the if statement.

NOTES: it states that for finding the odd numbers to use the NOT operator, but what target would I use?

I have checked my notes but could not find an example. If someone could give me a subtle hint it would be much appreciated.

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

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

    // End code 
}
Alex Yakir
Alex Yakir
5,425 Points

From what I understand, you need to find all the odd numbers that are divisible by 7 between 1-100.

For that you can use an "If" statement that checks two conditions:

  1. If "n" is not divisible by 2, that means its an odd number (you can use the remainder operator to accomplish this).
  2. Also if "n" is divisible by 7.

Hope this hint is subtle enough.

3 Answers

David Papandrew
David Papandrew
8,386 Points

Just to build on the other response:

10 % 2 == 0 //resolves to true

9 % 2 == 0 //resolves to false

n % 2 == 0 //resolves to true or false depending on the value of n

Michael Cafin
seal-mask
.a{fill-rule:evenodd;}techdegree
Michael Cafin
iOS Development Techdegree Student 1,221 Points

Thx for responding David for the add-on! It is much appreciated. I will check later today how to implement your suggestions!

I'll keep you posted!

Michael Cafin
seal-mask
.a{fill-rule:evenodd;}techdegree
Michael Cafin
iOS Development Techdegree Student 1,221 Points

My apologies for the wait but I want to thank both of you. It was truly helpful!

This is what I came up with

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