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

Tyler Dotson
PLUS
Tyler Dotson
Courses Plus Student 1,740 Points

check if something is odd and a multiple of seven. I feel like I am on the right track but I don't understand it

What do I have to do to check for an odd number and a multiple of 7

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

for n in 1...100 {
    // Enter your code below
    if n % 2 == 0 && 7 % 2 == 0 {
    results.append(n)
    }

    // End code 
}

2 Answers

james south
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
james south
Front End Web Development Techdegree Graduate 33,271 Points

right now you're checking if n is even and if 7 mod 2 is 0. a number is odd if n mod 2 is 1, and a number is divisible by another number if n mod x = 0. mod gives you the remainder of division, so if the result is 0, then the first number is divisible by the second. tweak it a little and let us know if you got it.

Tyler Dotson
Tyler Dotson
Courses Plus Student 1,740 Points

I was able to pass the challenge with your explanation but. I understand the odd number part but i thought you had to mod 7 by the number why is it n mod 7?

n mod 7 will determine whether n/7 returns remainder 0, which means that number is divisible by 7 (e.g. 14, 21, 35, 70, etc.)