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 trialjavier buitrago
3,083 PointsQuestion is saying that my string literal being assigned to output but be an interpolated string.
let firstValue = 2 let secondValue = 4
let product = firstValue * secondValue
let output = "("The") ("product") ("of") (firstValue) ("times") (secondValue) ("is") (product)."
// Enter your code below
let firstValue = 2
let secondValue = 4
let product = firstValue * secondValue
let output = "\("The") \("product") \("of") \(firstValue) \("times") \(secondValue) \("is") \(product)."
6 Answers
Jose Patarroyo
2,953 PointsHello,
To give a String value to the output constant, you should use the syntax:
"The product of x times y is z". Since you want to call the data stored on first and second value, the way to do it is like this:
"The product of (firstValue) times (secondValue) is (product)"
As you can see, the special character () call the data stored in the constants rather than writing the names of the constants (firsValue or secondValue)
Jose Patarroyo
2,953 PointsJus want to add, that for some reason the back slash was removed from my previous post. The syntax for the constants within the " " should be:
backSlash()
Hope you can understand what I mean
javier buitrago
3,083 PointsJose it is still giving me an error message.
Jose Patarroyo
2,953 Pointscan you show me your code?
Jose Patarroyo
2,953 PointsI found a way to write code within the post, let's see if it works. The correct syntax should be:
let output = "The product of \(firstValue) times \(secondValue) is \(product)"
Notice I only used the back slash followed by parentheses only when I want to view the data stored in the constants
javier buitrago
3,083 Pointsthank you jose, I was just missing the string interpolation bout your code was right.
"The product of (firstValue) times (secondValue) is(product)."
Jose Patarroyo
2,953 PointsUr welcome