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 trialIvan Cadena
2,949 Pointshelp with If statements
Im not sure what I'm doing wrong here, it keeps saying that its wrong. Can someone please explain?
var results: [Int] = []
for n in 1...100 { if n % 2 == 1 && n & * 7 == 0 { results.append(n)
}
4 Answers
Grant Thomas
13,705 PointsCleaning it up.
- It looks like you were missing a '}'
- I wrapped the expressions between your && operator
- changed the '& *' to '%'
var results: [Int] = []
for n in 1...100 {
if (n%2 == 1) && (n%7 == 0) {
results.append(n)
}
}
Zachary Kaufman
1,463 PointsAfter the && n there's a & that doesn't belong there. Try deleting that.
Ivan Cadena
2,949 Pointsit still says its wrong :(
Zachary Kaufman
1,463 PointsWould you mind telling me the error it gives you?
Ivan Cadena
2,949 PointsBummer! Make sure you are performing logical checks in the condition of the if statement
Zachary Kaufman
1,463 PointsOops I think I see the problem. You have if n * 7 == 0 it needs to be if n %7 ==0 and also delete the & after n. I think this will get it to work.
Ivan Cadena
2,949 Pointsthanks! it worked
Ivan Cadena
2,949 PointsIvan Cadena
2,949 Pointsthanks!