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 trialJohn Moron
1,658 PointsHow do i create a constant named language, println statement which will print the following string: "Learning Swift"
I need help
let language = "Swift"
2 Answers
Ethan Lowry
Courses Plus Student 7,323 PointsYou've got the creating of the constant part down. There are a number of ways you might print it along with a string:
- By string concatenation ("joining together" of strings):
let language = "Swift"
println("Learning " + language)
- Or, by string interpolation(a handy way to insert variables or other code into an existing string)
let language = "Swift"
println("Learning \(language)")
Hope that helps.
Chris Shaw
26,676 PointsHi John,
Earlier we learned about string interpolation which is how we include the value of a variable within a println
statement for example, in this task we need to use interpolation to include the value of language
within a println
declaration.
let language = "Swift"
println("Learning \(language)")
Happy coding!
John Moron
1,658 PointsOh i had to do it like that thanks Chris.
John Moron
1,658 PointsJohn Moron
1,658 PointsSo can use ether way?
Ethan Lowry
Courses Plus Student 7,323 PointsEthan Lowry
Courses Plus Student 7,323 PointsBoth will give the same result, most people would prefer the interpolation method in cases like this. I'm not sure whether the Treehouse challenge will accept both, so try the other if it fails :)
John Moron
1,658 PointsJohn Moron
1,658 PointsI understand thanks Ethen:).
Chris Shaw
26,676 PointsChris Shaw
26,676 PointsEthan Lowry, this course uses best practises which in this case is interpolation and is what the challenge is expecting and is how the language is taught to students.