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 trialRicardo Gonzalez
2,286 PointsI don't know how to finish my code.
I think I am doing right but don't know how to finish it.
var results: [Int] = []
for n in 1...100 {
if n % 3 && n {
results.append(n)
}
}
1 Answer
Steven Deutsch
21,046 PointsHey Ricardo Gonzalez,
You're on the right track. You have the append part correct, we just have to look at the the conditions you are evaluating for. You need to check if each case of n is true for two conditions. These are if n is odd and if n is a multiple of 7.
To check if n is an odd number, we can use the remainder operator and 2. If the result is not equal to 0, this mean the number is not even because it did not divide by 2 with no remainder. We then use the AND operator to check if this number satisfies the condition where n is a multiple of 7.
To check if n is a multiple of 7, we do something very similar to checking if n is odd. Here we will use the remainder operator but this time with 7. We will check if the result is equal to zero. If it is, this means that the number was successfully divided by 7 without a remainder and that the number must also be a multiple of 7.
var results: [Int] = []
for n in 1...100 {
// Enter your code below
if n % 2 != 0 && n % 7 == 0 {
results.append(n)
}
// End code
}
Good Luck
Ricardo Gonzalez
2,286 PointsRicardo Gonzalez
2,286 PointsThanks Steven. I appreciate your help.