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 trialAshley Livingston
6,931 PointsMy code compiles and accomplishes the task but it's still not correct
I can't figure out the answer the challenge is looking for.
The challenge:
You are provided with a constant array named months that contains 3 consecutive numbers starting at 1. Using a for-in loop and an if statement, print out "January" when you encounter a 1, "February" when you encounter a 2, and finally "March" when you encounter a 3.
My code:
let months = [1, 2, 3]
for month in months {
if month == 1 {
print("January")
} else if month == 2 {
print("February")
} else if month == 3 {
print("March")
}
}
It compiles and does what it is supposed to but I'm still getting the answer wrong. Any ideas?
1 Answer
Tyler Simko
5,610 PointsTry using println() instead of print().
Ashley Livingston
6,931 PointsAshley Livingston
6,931 Pointsandddddd it works! Thanks.