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 trialJeffrey Hayes
141 PointsHow to code the println using Interpolation Language = "LearningSwift"
Have written the Function let language = "Swift" Attempt to write the function Println but have failed repeatedly. ?
let language = "Swift"
println("language: Swift\n Learning")
3 Answers
Thorsten Herbst
11,935 PointsTry this. let language = "Swift" println("language: \n (language) Learning") \n ---> new Line (language) --> let substitution
Hope that helps Greets Thorsten
Unsubscribed User
15,508 PointsHi Jeffrey,
To further clarify Thorsten's answer, let's address what you've done.
let language = "Swift"
println("language: Swift\n Learning")
You refer to these two lines as functions. Whilst println()
is a function (we know this because of its parentheses), let language = "Swift"
is not. It's what is called a variable declaration. In other words, you're declaring what the variable is called (language
) and then what value it holds ("Swift"
).
With that out of the way, let's address how to interpolate this variable in to a String.
So our println()
function holds a String. To interpolate a variable in to a String, we do this:
println("This is an \(variableName) String.")
All in all, to answer your question in context, we would simply write:
let language = "Swift"
println("language: \(language) Learning") // This will print to the console;
// language: Swift Learning
I hope this helps your understanding!
bouchrakerr
13,323 Pointsprintln("Learning (language)")