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 trialDenali Lord
Courses Plus Student 1,955 PointsThis is a tough one...
So I have created my if loop and used the && operator as the question asks, " for the odd numbers and the multiples of 7. Not really sure where to go from here...
var results: [Int] = []
for n in 1...100 {
// Enter your code below
if results {
(!2 % 0) && (n * 7)
// End code
}
2 Answers
Jennifer Nordell
Treehouse TeacherFirst, we're not going to evaluate anything in results. Results is empty and they want us to fill it up. Secondly, never divide by 0. It's just a no no, because well... it can't be done :) Here's what we want the code to do. We want it to start at 1 and ask is 1 an odd number? Yes! Is it evenly divisible by 7? No!. Ok skip that one. Then we do the same thing and check 2. Which has a result of No on both questions. But when we get to 7 things get more interesting. Is 7 odd? Yes! Is it evenly divisible by 7? Yes! Ok add it to our results array. And here's how we do it:
var results: [Int] = []
for n in 1...100 {
// Enter your code below
if(n % 7 == 0 && n % 2 != 0) {
results.append(n)
}
// End code
}
Any number % 2 will either return a 0 or a 1. If it returns a 1 it's odd. If it returns a 0 it's even. Hope this helps!
Martin Wilter
iOS Development Techdegree Student 8,782 PointsHi Denali,
There are a few syntax issues with your code that might prevent you from progressing properly, so below I have provided some pseudo code to help you out. Replace the comment markers and anything between them with your own code:
for n in 1...100 {
// Enter your code below
if /* the number n is odd */ && /* the number n is a multiple of 7 */ {
/* append the numner n to the array var results */
}
// End code
}