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 trialBobby Smith
1,985 PointsI have attempted this a couple of times, but I don't seem to come up with the proper solution
I have attempted this a couple of times, but I don't seem to come up with the proper solution
var results: [Int] = []
for n in 1...100 {
if n % 7 == n % 2 == 1
}
3 Answers
jonlunsford
15,480 PointsAnthony: Here is one example. This code will check if the integer 21 is both a multiple of 7, and an odd number:
if (21 % 7 == 0) && (21 % 2 > 0) {
print("Yeah")
} else {
print("Neah")
}
This is just one way to do this. Note I have hardcoded conditional values. Both conditions must be true to print "Yeah" and if not it will print "Neah".
jonlunsford
15,480 PointsAnthony, your IF statement is incomplete. I would go back and review the elements for an if statement. Also, the challenge is asking for multiples of 7. To check this you would check the condition that (n % 7 == 0). For example if n was 14, there would be no remainder since 14 is a multiple of 7, and this condition would evaluate to True. Then you need statements to do something in this case. Same thing for the other conditions. An IF statement should evaluate a condition then execute code if the condition is met.
Bobby Smith
1,985 Pointsvar results: [Int] = []
for n in 1...100 if (n % 2 == 1) && (n % 7 == 0) { results.append() }
jonlunsford
15,480 PointsYour code looks correct now, did it work for you?