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 trialAramik YOUSEFZADEH
Courses Plus Student 895 PointsCode Error
I can not find my symtax problem.
var results : [int] = []
for n in 1...100 {
// Enter your code below
if (( n % 7 == 0) && (n % 2 !=0 ))
{
result.append (n)
n+=1
} else { n+=1 }
// End code
}
2 Answers
Jeff McDivitt
23,970 Points- There is no need for parentheses in Swift
- Add an s on result
- You do not need n += 1
var results: [Int] = []
for n in 1...100 {
// Enter your code below
if n % 7 == 0 && n % 2 != 0 {
results.append(n)
}
// End code
}
Aramik YOUSEFZADEH
Courses Plus Student 895 PointsThanks a lot, I appreciate it.
Tiwong Nance, Jr.
19,650 PointsTiwong Nance, Jr.
19,650 PointsHello Aramik. I think I've found the syntax error. You have too many parentheses in the if conditional -
((n & 7 == 0) && (n % 2 != 0))
try this: (n & 7 == 0) && (n % 2 != 0)
Also, the [int] should have a capital I(case sensitive), so put [Int].
The third error is the append value statement. The parentheses must be directly after append without spaces. Make sure to add an s to result, so that it matches the variable called at the top. It should look something like this:
results.append(n)
As far as the n+=1 & else statement, the two are not necessary, but shouldn't cause an error if not removed.
Hope this was helpful.