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 trialRoy Reuveni
2,621 PointsHey there, I'm trying to figure out how to write the right condition to check if a number is both odd and a 7 multiple
Im using this condition in the Collections and Control Flow's task:
if n % 2 ==0 && n % 7 == 0 { }
What's not working here? Thanks! Roy
var results: [Int] = []
for n in 1...100 {
// Enter your code below
if n % 2 == 0 && n % 7 == 0 {
results.append(n)
}
// End code
}
3 Answers
Jennifer Nordell
Treehouse TeacherHi there! Oh wow you're close. In fact, if I change one single character it passes. And I'll give you a hint. I change an equal sign to an exclamation remark. Remember, if a number % 2 is equal to 0 it is even... not odd
Give it another go with these hints in mind!
surajgantedi
8,555 PointsAs it says use not operator i.e !(n%2 == 0) for n in 1...100 { // Enter your code below if !(n % 2 == 0) && (n % 7 == 0){ results.append(n) } else{ print("not even") }
}
Roy Reuveni
2,621 PointsRoy Reuveni
2,621 PointsAhhh! Can't believe I missed that, you're so right!
Jennifer Nordell
Treehouse TeacherJennifer Nordell
Treehouse TeacherRoy Reuveni You're quite welcome!