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 trialBrandon Sherwood
Courses Plus Student 1,090 PointsWhat am i doing wrong?
This is what it is telling me:
Double check your logical conditions to ensure that the value being appended is both odd and a multiple of 7.
Can someone please tell me what to fix, I'm pretty sure it has something to do with my if statement parameters.
var results: [Int] = []
for n in 1...100 {
var multiplesOfSeven = n * 7
var oddNumbers = n % 3
if multiplesOfSeven < 100 && oddNumbers < 100 {
results.append(multiplesOfSeven)
results.append(oddNumbers)
}
}
2 Answers
Nawfal Cherkaoui
14,539 Pointsvar results: [Int] = []
for n in 1...100 {
// if n is an odd number and n also a multiple of 7 then append n to the array
if n % 2 != 0 && n % 7 == 0 {
results.append(n)
}
}
/*
try printing your result and you'll see that you only appending the result of
(n%3) and (n * 7) that are less than 100
*/
for a in results {
println(a)
}
agreatdaytocode
24,757 PointsWhat you are doing is appending numbers that are less than 100.
var results: [Int] = []
for n in 1...100 {
// Enter your code below
if n % 2 != 0 && n % 7 == 0 { // We are checking for odd and multiples of 7
results.append(n)
}
// End code
}
agreatdaytocode
24,757 Pointsagreatdaytocode
24,757 PointsNice job Nawfal, good answer here.