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

codyl
codyl
4,704 Points

I don't get it -- my code seems absolutely correct.

I'm checking to see if it's even (via n % 2 ==0) I'm checking to see if it's divisible by 7 (via n % 7 ==0) I'm adding all #s that fit both to the results array I put this code in swift and printed the array (14,28,56,70,84,98) Plus the question asks how many there are, so I have it print results.count

So what's the beef?

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

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

1 Answer

codyl
codyl
4,704 Points

omg I'm dumb. I was checking for all #'s that are EVEN and divisable by 7, question was for all odd. I know how to change it to check for odd ("!= 0" rather than "== 0"), I just read it wrong. Oh man I feel silly. I hope this 'answer' helps anyone else that might look up this quiz :)