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

Help. I'm stuck on this challenge. Why won't the following work?

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

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

for n in 1...100 

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

    // End code    

2 Answers

Hi Jane Rhee,

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

What you're saying here is if n is odd and n times 7 equals 0 then append the value of n to list. But n times 7 will never be 0 unless if n is 0 and this is not what they asked in the assignment. They wanted you to also append any multiple of 7.

Hint: if n % 2 == 0 then n is a multiple of 2.

You can apply the same logic to figure out how to know if something is a multiple of 7.

Good luck!

the code was rewritten and i'm still stumped. I am wondering if the problem lies in the writing of appending the results of values? I want to write: if n is odd && if n is a multiplier of 7 then append the results values.

var results: [Int] = []

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

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

I checked your answer:

var results: [Int] = []

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

It is correct.

ah! thank you for your help on this one! the code was not running because of a missing bracket somewhere in there, but I figured it out & the code finally passed. thanks again! :)