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 trialbill huggin
126 PointsI am stumped here...apparently I am printing Learning Swift Swift instead of "Learning Swift"
I am stumped here...apparently I am printing "Learning Swift Swift" instead of "Learning Swift"
What is correct
let language = "Swift"
println("Learning Swift \(language)")
3 Answers
John Magee
Courses Plus Student 9,058 PointsWell - you tell the program to print "Learning Swift" and then you include the variable language that you defined earlier. So you are basically saying "Out put Learning Swift and then follow it with the content of the variable language I set earlier (as Swift)
Jacob McCaig
7,201 Points(language) = "Swift"
You're doing it twice.
John Rainier Rivera
6,355 Pointslet language = "Swift" println("Learning (language)")
Jacob McCaig
7,201 PointsA println()
simply outputs to the console whatever you put in it. You are essentially wanting to print "Learning " + whateverIsInTheLanguageVariable.
To do this you use string interpolation. The syntax is "your string here \(yourVariableHere)"
and to get that to output to the console, you would place it in a println()
function.