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 trialAbotsi Godwin
Courses Plus Student 1,400 PointsStrings
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.
// Enter your code below
let name = "Abotsi"
3 Answers
Jonathan Ruiz
2,998 PointsFor the first part it asks to create an interpolated string of your name and greeting. You already wrote the constant with your name. Now you have to declare a constant named greeting that combines a string with the name constant you created. To do this in the “ “ you use this syntax ( ). It would end up looking like this
let example = “example”
let stringInterpolation = “This is my \(example)”
I’m using ( ) around the name of the constant example I created with a string value. For this example the code would look like this.
let name = "Elliot Alderson"
let greeting = "Hi there, \(name)"
The second part wants you to concate two string values and assign it to constant finalGreeting. To concatenate two strings you use an assignment operator ( + ). It would be like this.
let example = "example"
let stringConcatenation = example + "of how you concatenate strings"
I declare the constant stringConcatentation and this time instead of using brackets and a back slash. I just type the name of the constant in this case example afterwords put the assignment operator then the new string I want to concatenate with. Hope this helps !
Jonathan Ruiz
2,998 PointsThe first part wants you to use string interpolation to assign the name constant as part of the string in the greeting constant. That way it reads "Hi there, "Elliot Alderson"
let name = "Elliot Alderson"
let greeting = "Hi there, \(name)"
this second part it wants string concatenation. The way this is set up is using the name of the constant then the assignment operator + and then writing out the new string. If you write the constant finalGreeting with string interpolation it won't accept your answer even if it prints the correct phrase.
let name = "Elliot Alderson"
let greeting = "Hi there, \(name)"
let finalGreeting = greeting + ". How are you ?"
I put the period and then added a space before typing out How so that way it matches the string it wanted. Hope this helps!
Abotsi Godwin
Courses Plus Student 1,400 PointsThank you. I appreciate that a lot
Abotsi Godwin
Courses Plus Student 1,400 PointsAbotsi Godwin
Courses Plus Student 1,400 PointsJonathan thanks for the help, I am back on here now and still it's not working. Really stuck on this string