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 trialAyush Behere
566 PointsCannot compile my response
Hi,
I'm having a problem with getting the answer to this challenge. I type my response in xcode and it works perfectly, so a bit confused about why it's not working here. Thanks in advance!
let name = "Ayush" let greeting = "("Hi there"), (name)."
// Enter your code below
let name = "Ayush"
let greeting = "\("Hi there"), \(name)."
1 Answer
Steven Deutsch
21,046 PointsHey Ayush Behere,
You only need to use String Interpolation to convert the values stored inside of a variable/constant into a String. The string, "Hi there, " is already a string literal. Therefore, you don't need to use interpolation here.
See my code below:
// Enter your code below
let name = "Ayush"
let greeting = "Hi there, \(name)."
Good Luck!
Ayush Behere
566 PointsAyush Behere
566 PointsThanks for your response Steven! I guess I think I made that mistake because in the video, when combining the street number with the street name, interpolation was used for the street number. Is this because that was a number and not a string, whereas "Hi there," is already a string?
Steven Deutsch
21,046 PointsSteven Deutsch
21,046 PointsYes, if you had some variable, number lets call it, that is storing an integer value of 4 - you would use String Interpolation to extract that value from the number variable and write it as a string. However, if you wanted to join that number with what is known as a String literal, you wouldn't have to use interpolation on the String literal, because it is already a String.
Keep in mind that we would do the same thing to extract the value of number if it was a type other than Int, let's say it was a String value as well. You use String interpolation to extract the value from the variable or constant. If you are writing the value out, literally, you don't need to use interpolation.
Good Luck
Ayush Behere
566 PointsAyush Behere
566 PointsThat helps a lot, thanks!