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 trialKris Larsen
8,015 Pointsif statement
This is the challenge:
Your job is to write an if statement inside the for loop to carry out the desired checks.
If the number is indeed both an odd number and a multiple of 7, append the value to the results array provided.
I dont know what I shall do to find the odd and multiple of 7? I am lost.
var results: [Int] = [7, 21, 35, 49, 63, 77, 91]
for n in 1...100 {
// Enter your code below
if ???
// End code
}
1 Answer
Steve Hunter
57,712 PointsHi Kris,
If you use the mod (modulo, modulus?) function that gives you the remainder of a division function. The operator is a percent sign. So 4 % 2
returns zero as 4 divided by two leaves no remainder. So, 7 % 2
gives you 1 for the same reason.
Testing for "oddness" can be done by checking if number % 2 != 0
or number % 2 == 1
.
I hope that helps - and have a look at this post on the same point from yesterday.
Cheers,
Steve.