iOS Swift Collections and Control Flow Control Flow With Conditional Statements Working With Logical Operators

codyl
codyl
4,688 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,688 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 :)