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 trialYong Wha Hong
1,237 PointsLogical Operators Challenge
Why is this wrong for this challenge? It is saying I did not set the logical conditions correctly.
if n % 3 == 0 && n % 7 == 0 { results.append(n) }
3 Answers
Michael Reining
10,101 PointsHi there,
The challenge is looking for something different.
You are looking for all numbers that are divisible by 3 and 7. That is not what the challenge is asking.
It is asking that you find all odd numbers that are divisible by 7.
The code for that looks like this.
var results: [Int] = []
for n in 1...100 {
// Enter your code below
if n % 2 != 0 && n % 7 == 0 {
results.append(n)
}
// End code
}
results
I hope that helps,
Mike
PS: Thanks to the awesome resources on Team Treehouse, I just launched my first app. :-)
Raymond Carter, Jr.
iOS Development Techdegree Student 488 Pointscan you break this down step by step I'm completely lost?
Loy Lee
Courses Plus Student 1,647 PointsI think it's like this
n % 2 compares each of 1...100, which will result in some numbers with a remainder value. != 0 has a remainder that is not 0
n & 7 compares each of 1...100, which will result in some numbers with a remainder value. == 0 has a remainder of 0
&& both conditions apply
results.append(n) This will append the number of numbers found in 1...100 from the task (n) to results