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 trialMarco Leo
1,007 PointsCan't seem to figure it out?
Can someone explain it more to me?
Thanks,
let months = [1, 2, 3]
for month in months {
if month == 1 {
println["January"]
} else if month == 2{
println["February"]
} else if month == 3{
println["March"]
} else {
println[month]
}
}
2 Answers
kjvswift93
13,515 PointsYou are very close. Your first issue is that you have incorrectly written your println functions by using brackets instead of parenthesis. i.e. println["January"] instead of println("January"). Then, you can delete that final else clause because it is unnecessary. The code should end after println("March") }.
kjvswift93
13,515 Pointsno problem. So the final solution should be this. See if yours matches.
let months = [1, 2, 3]
for month in months {
if month == 1 {
println("January")
} else if month == 2 {
println("February")
} else if month == 3 {
println("March")
}
}
Marco Leo
1,007 PointsMarco Leo
1,007 PointsThank you, you were very helpful.