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 trialche Robinson
Courses Plus Student 477 Pointswhy is this not working but it does in swift
let name = "Che'" let greeting = "Hi,there"
let interpolatedGreeting = "(greeting), (name)"
// Enter your code below
let name = "Che'"
let greeting = "Hi,there"
let interpolatedGreeting = "\(greeting), \(name)"
2 Answers
Matthew Young
5,133 PointsNot 100% certain what you're asking, but I'm assuming you're comparing the top code with the code in the strings.swift file.
The top code where you define the constant interpolatedGreeting is missing the backslash before each parantheses closure. Notice where they are in the strings.swift file under the constant of the same name. Without it, you're just setting interpolatedGreeting with the string literal "(greeting), (name)".
For more information on String Interpolation, check out The Swift Programming Language - Strings and Characters - String Interpolation
Keli'i Martin
8,227 PointsIf you are trying to pass the challenge, the reason it isn't working is because the challenge asks you to first declare a constant called name
and assign it your name. It then asks that you declare a constant called greeting
that uses string interpolation to the literal string "Hi there, "
with the constant name
. The challenges are very particular about the output they ask for.
In your case, the value of greeting
should in the end contain the string Hi there, Che'."
Hope this helps!