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 trialpetersindingkristensen
709 Pointslet interpolatedAddress = "\(country), \(state), \(city)" doesn't work
I write exactly the same code as in the video, but xcode don't recognize it. Also I'm stuck in the following coding challenge with the same problem
Oliver Duncan
16,642 PointsXCode doesn't recognize it? If you're in a playground, make sure you're importing Foundation or UIKit.
Simon Di Giovanni
8,429 PointsHi Peter
There is nothing wrong with what you've written there.
If you're receiving an error, there must be a spelling mistake with one of your constants.
Could you please copy and paste your whole playground, and I'll check it for you?
Please check the markdown cheat sheet for Info on how to correctly paste the code
Cheers
Simon
petersindingkristensen
709 PointsHi guys.
This is what I wrote. Pretty much, exactly what was written in the video:
//: [Previous](@previous)
// concatenation
let country = "United States of America" let state = "North Carolina" let city = "Charlotte" let street = "West Street"
let concatenatedAddress = country + ", " + state + ", " city let interpolatedAddress = "(country), (state), (city)"
// String Interpolation
let interpolatedStreetAddress = "(222) + (street)"
//: [Next](@next)
But the program doesnt recognize the lines: let interpolatedAddress = "(country), (state), (city)" and let interpolatedStreetAddress = "(222) + (street)"
The challenge I'm having trouble with is this one:
Often when we use apps, we enter our name during the sign up process. Later, inside the app, we see many greetings that reference us by name.
This feature can be implemented quite simply using string interpolation. In this task we're going to declare two strings. First, declare a constant named name and assign to it a String containing your name.
Second, declare a constant named greeting. Set the value of greeting to an interpolated string that combines "Hi there, " with the string stored in the name constant.
As an example, the final value of greeting could be "Hi there, Linda.".
Note: Make sure to enter a period/full stop after your name in the final string.
I wrote something like:
let name = "peter" let greeting = "Hi there"
let interpolatedGreeting = "(greeting), (name)."
But it doesn't work either..
thanks :)
peter
2 Answers
Alia Khan
3,733 PointsHi for the challenge try this :)
''' Swift let name = "Peter"
let greeting = "Hi there, (name)" ''' The challenge is asking you to first declare a constant called name and assign it to a string containing your name which you have done perfectly :)
The second part is asking you to declare a constant named greeting and set the value of greeting to an interpolated string that combines "Hi there, " with the string stored in the name constant.
An interpolated string is a string that uses string interpolation.
This is the syntax for string interpolation. Its a back space followed by parenthesis "()".
Inside the string which is the 2 quotation marks you write Hello there, and then in the brackets you write the constant name. so let greeting looks like this -
let greeting = "Hi there, (name)"
Hope that helps :)
if you need any help just let me know
petersindingkristensen
709 PointsThat's it. Thank you :)
Alia Khan
3,733 PointsAlia Khan
3,733 PointsHi what is the challenge asking you to do. what are the instructions