Welcome to the Treehouse Community
Looking to learn something new?
Albert G4,142 Points
Stuck on coding challenge
not sure whats wrong with my code for step two
// Enter your code below let firstValue = 2 let secondValue = 4 let product = firstValue * secondValue let output = " \("the product of") \(firstValue) \("times") \(secondValue) \("is")\(product)"
You can't use
\() around plain text inside of a string.
Swift will try to evaluate the text, which will cause an syntax error. You should omit the () so that Swift understands you aren't trying to evaluate that piece of code but you want it to be part of the string.
let greeting = "\("Hello There"), \(name)"
let greeting = "Hello There, \(name)
I hope this hint will help you.
If you continue to struggle, jutst ask below and I'll give you additional hints :)
Good luck! ~Alex
let firstValue = 2 let secondValue = 4 let product = firstValue * secondValue let output = "The product of \(firstValue) times \(secondValue) is \(product)"
You didn't format the string interpolation correctly. We never created any constants named "the product of", or "times". The constants we have decried are "firstValue", "secondValue", and "output". These are the names we will use to represent an integer number within the sentence the challenge asks us to make based upon what the values of the the constants firstValue and secondValue are, in this case it is 2 and 4, respectively. The string assigned to the constant output should read "The product of 2 times 4 is 8". Within this string, the values 2, 4, and, 8 will be replaced with the names we assigned them to in between a backslash and pair of parentheses. "(firstValue)" therefore is really "2", with the name of the constant assigned to it "interpolated" (synonymn for inserted or replaced) .