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 trialJesus Cordoba
1,414 PointsIF/For Code Task Challenge
Even do my code works in Xcode. In the website just does not seems to like and approve it. I am trying to get/check the multiples of 7 (from 1 to 100) AND the odd numbers, if booth conditions are True ten i have to insert them in the array.
var results: [Int] = []
var nuevoValor = 0
var impar = 0
for n in 1...100 {
// Enter your code below
nuevoValor = (n * 7)
impar = nuevoValor % 3
if impar == 2 {
results.append(nuevoValor) }
// End code
}
1 Answer
Farhad Mohammad Afzali
5,007 PointsHello, you need to put your conditions in a formula rather than hard coding them. Please check my solution below.
var results: [Int] = []
for n in 1...100 {
// Enter your code below
if (n % 7 == 0 && n % 2 != 0) {
results.append(n) }
// End code
}
Hope it helps
Jesus Cordoba
1,414 PointsJesus Cordoba
1,414 PointsJust in my second day around here. Β΄New guyΒ΄I guess I am thinking too much. Thanks I appreciate the lesson. Regards from Mexico!