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!
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
I don't know why the code doesn't work
"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."
That was the scenario
I checked 3 times and I think I code it correctly but I don't know what's the problem. Would you please explain why the code does not work?
// Enter your code below let greeting = "Hi there, " let name = "Jumanah" let interpolatedGreetingName = "\(greeting), \(name), \(".")"
Jhoan Arango14,575 Points
Well you have everything good, but the only thing is that the period should not be interpolated.
let interpolatedGreetingName = "\(greeting), \(name)." // This should do the job. // or you can do this, but not sure if this will allow you to pass the challenge. // But in a real project you could do this, I do not recommended it since it's not good looking code // but for the purpose of this example, I wanted to show you. let dot = "." let interpolatedGreetingName = "\(greeting), \(name)\(dot)"
When you use the "String interpolation characters" you tell swift to ignore those as strings, and call a property instead to complete the sentence. By doing it the way you were doing it, swift was not recognizing the dot as a string. That's just an example of what you can do with String interpolation.