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 trial

iOS Swift Basics Swift Types String Manipulation

*[SOLVED]* Not really a question at all just a statement that this activity is broken... The code is 100% correct

i have tried numerous variations on this activity and it is not allowing me to pass. This must be broken there is no way this is incorrect. If this was being coded on a more suitable software the results would be printing perfectly fine. This is just like a testcase from College when i learned Java. They are all broken and multiple ways are accepted however you fail every time to an unrelated issue that isn't coding specific.

strings.swift
// Enter your code below
let name = "Dominick"
let greeting = "\("Hi there, ") \(name)"
let literal = " How are you"
let finalGreeting = greeting + "." + literal + "?" 

Solved. Just like i thought. Just an issues with the website test cases them self.... All i needed to do was change the way i used the punctuation. SMH..... these test cases are a bit flimsy

Jason Anders
Jason Anders
Treehouse Moderator 145,858 Points

Hi Dominick Rizzo

I definitely would not say "flimsy", just specific (as it will be in the "Real World").
Instructions need to be read thoroughly, carefully, and they need to be followed exactly, just as you would with coding a project for a client or an employer.

So, according to the instructions, your code is not 100% correct. It is functional, yes, but ultimately, incorrect. If a client or company you are working for asks for something specific, and you decide to 'improvise,' odds are the client / company is going to reject your code and tell you to redo it.

Coding is very specific, both here and in the 'working' world. In code, just because something works does not mean it is correct. This is why challenges and the instructions are very specific. It is to help ready you for what is to come.

Keep Coding! :) :dizzy:

P.S. I've also marked your post as "Solved"

1 Answer

Michael Hulet
Michael Hulet
47,912 Points

Hi Dominick,

I concur with Jason on this that it's important to pay attention to just what the challenge asks for. That being said, this code is likely failing because there are a few syntax errors on line 3. Specifically, your punctuation with string interpolation isn't quite right. If you learned Java in college, you're probably familiar with the concept of escape characters. They're not actual characters, but instead just placeholders for a special character that's supposed to go there instead, like \n or \t. One thing to note about them is that they all start with a \. In Swift, string interpolation is essentially a generic escape sequence, but instead of a single character after the \, there's parentheses with an expression inside, and the result of that expression is pasted directly into the string as-is, and the \() are removed from the output. Everything between the parentheses are read by the Swift compiler, and anything there must be valid Swift. Your second attempt at it (\(name)) looks great! Unfortunately, there are a few syntax errors earlier in that string. First of all, you don't need to place extra quotation marks (") inside the parentheses. Since these are there, Swift sees a string end and then a symbol immediately begin with nothing in between, which isn't something it knows how to handle. Furthermore, there's a comma (,) inside the parentheses, where I think you meant to leave it outside. When it's inside the parentheses, it's part of compiler-enforced Swift syntax, but when it's outside the parentheses, it's just a comma used as punctuation in the string. I believe the challenge will pass after those issues are fixed. I realize this question is marked as solved when this was posted, but hopefully this will shed some light on what went wrong in the first place. Happy coding!