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 trialSean Lafferty
3,029 PointsAnother entirely wrong attempt
Very difficult to grasp. I have been doing the practice videos and trying to revise but I am struggling to understand! Does nayone have any advice or ideas on how I can get a better grasp of how to get through these challenges rather than asking for help on every one! :(
var results: [Int] = []
for n in 1...100 {
// Enter your code below
if !n%2 || n%7
n.append()
// End code
}
1 Answer
Jennifer Nordell
Treehouse TeacherHi there! I see that you've been working on this and I looked back at my comment to you on your previous post and one of the videos opens for me, but the other one doesn't and I have no idea why.
But I'd like to at least congratulate you on understanding that the modulus/modulo operator should be used here and the append method.
Here's how I did it (with comments):
var results: [Int] = []
for n in 1...100 {
// Enter your code below
if n % 2 != 0 && n % 7 == 0 { //if the number is odd and evenly divisible by 7
results.append(n) //append the number to the results array
}
// End code
}
Ok so if a number is evenly divisible by another number, it will have a remainder of 0. Even numbers are all numbers that are evenly divisible by 2. So first I say if the number is not evenly divisible by two (ie it is odd) and the number is evenly divisible by 7, then take that number and append it to the results
array.
This means that the resulting array will contain the numbers: 7, 21, 35, 49, 63, 77, 91.
Hope this clarifies things!
As for finding other answers, you can always search the forums. Take a look at this link which contains no less than 3 pages of students who have previously had this question.
Sean Lafferty
3,029 PointsSean Lafferty
3,029 PointsThanks again for explaining, you are a great help! I'm going to recap some of my previous work and get back on the horse!
Sean