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 trialVanessa Jimenez
691 PointsNot sure what I am doing wrong...
It's saying I should append the correct value but I believe I am ?
var results: [Int] = []
for n in 1...100 {
// Enter your code below
if n % 2 != 0 && n % 7 == 0
results.append(n)
}
// End code
2 Answers
Emin Grbo
13,092 PointsIt seems you are only lacking the curly braces for the IF statement :) Before, the append method was only executed 1 i think.
for n in 1...100 {
// Enter your code below
if n % 2 != 0 && n % 7 == 0{
results.append(n)
}
}
Jennifer Nordell
Treehouse TeacherHi there! You're doing well and your logic is solid, but your syntax is a bit off. In some languages, you may put what happens if an expression evaluates to true on the same line as an if statement and have it work without curly braces. This is not true of Swift. The opening and closing curly braces for an if
statement are non-optional. Just as your for
loop has opening and closing curly braces, your if
statement also needs them:
for n in 1...100 { // begin for loop
if expression { // begin if
// do something here
} // end if
} // end for loop
Hope this helps!
Vanessa Jimenez
691 PointsVanessa Jimenez
691 PointsEmin Grbo Why do I need a second set of curly braces inside?