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 trial

iOS Swift Basics (retired) Types Printing Results

println challenge question

I’m not sure I’m understanding the question here. It says:

“Given the constant named language, write a println statement which will print the following string: "Learning Swift". (Remember to use the language constant within the string you pass to your println statement).”

I’m given the line:

let language = "Swift"

I added the line:

println("Learning " + language)

My understanding, backed up by replicating the code in an xcode playground, is that this should output the line “Learning Swift” as indicated by the instructions.

I get the feedback that:

“Bummer! You need to interpolate the value of the 'language' constant into the string you pass to ‘println’."

My initial thought from this feedback was that perhaps there was a problem with directly using a constant in the println command, so I then replaced my answer with this code:

var verb = "Learn " var lesson = verb + language println(lesson)

This answer also works in xcode, and also gets the same feedback. I’m afraid I’m at a loss.

println.swift
let language = "Swift"
var verb = "Learn "
var lesson = verb + language 
println(lesson)

2 Answers

Stone Preston
Stone Preston
42,016 Points

the error states: “Bummer! You need to interpolate the value of the 'language' constant into the string you pass to ‘println’."

you are using string concatenation (joining strings together with the + operator), however you need to use string interpolation:

String interpolation is a way to construct a new String value from a mix of constants, variables, literals, and expressions by including their values inside a string literal. Each item that you insert into the string literal is wrapped in a pair of parentheses, prefixed by a backslash:

the swift eBook provides the following example code:

let multiplier = 3
let message = "\(multiplier) times 2.5 is \(Double(multiplier) * 2.5)"
// message is "3 times 2.5 is 7.5"

so to interpolate the language constant into the string you would use:

let language = "Swift"
println("Learning \(language)")

Thank you, Stone. I'll give that a try.