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 trialJonathan Holland
iOS Development Techdegree Student 4,037 PointsThis challenge has really stumped me. I can't figure out how to check to see if the number is not even and attach result
i tried: "if n %2 != 0 && n / 7 { results = n }, but it gives error saying that i can't use "&&" with a BOOL and INT. and apparently i'm not attaching results properly to array.
var results: [Int] = []
for n in 1...100 {
// Enter your code below
// End code
}
2 Answers
Tosin Peters
9,541 PointsInstead of n/7 you should use n % 7 == 0 to find if the number is divisible by 7 and also where you have result = n you should say result.append(n) ex
if n % 2 != 0 && n % 7 == 0 {
results.append(n)
}
Curtis Bridges
17,720 PointsYou can check for a remainder rather than using outright division:
if n % 2 != 0 && n % 7 == 0 {
// n is not even and is divisible by 7
}
In this case, both sides of the condition are booleans.
Jonathan Holland
iOS Development Techdegree Student 4,037 PointsThanks for your help
Jonathan Holland
iOS Development Techdegree Student 4,037 PointsJonathan Holland
iOS Development Techdegree Student 4,037 Pointsthanks! was this covered in the TechDegree? Because I don't remember anything with "%" and using it to check if something is divisible or not-equal to something..
Tosin Peters
9,541 PointsTosin Peters
9,541 PointsThe symbol (%) is known as the modulus operator, or mod for short. It has the same functionality as the modulus operator in basic math. I'm not sure if it was been taught in the TechDegree program but there are many resources on it online