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 trialDawson Young
512 PointsDon't understand how to write this code
I keep getting errors when I try to add the && operator
var results: [Int] = []
for n in 1...100 {
// Enter your code below
if n % 3 {
print(n)
}
// End code
}
1 Answer
Keli'i Martin
8,227 PointsThe first thing I would point out is that you can't use just n % 3
in an if statement, because that doesn't return a boolean value. You need to compare it to something, which is probably why you're having an issue using the && operator. So you'd need to do something like
if n % 3 == 0
and then you should be able to use the && operator. Hope this helps.