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 code challenge working in Xcode, but not Treehouse compiler. What am I doing wrong?

I'm in the Swift 2.0 Basics course, in the "Recap: Swift Types" section. On task 2 of 2 I'm getting the "Bummer" message which reads "The string literal being assigned to output must be an interpolated string that evaluates firstValue, secondValue and product"

Here's my code:

let firstValue = 500
let secondValue = 5
let product = firstValue * secondValue

let output = "\("The product of") \(firstValue) \("times") \(secondValue) \("is") \(product)"

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

You only need the backslash and parentheses around things that are a variable name to be interpreted. firstValue is a variable name. "The product of" is not a variable name. Take a look at the output line you need:

let output = "The product of \(firstValue) times \(secondValue) is \(product)" 

YESSS! Thank you so much! Not sure why it worked in Xcode, but I'm glad you taught me the proper syntax because I would'be been doing a lot of extra work for myself in the future. Thanks again!

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

You're quite welcome! And yes, it's good to get used to it now because this string interpolation stuff comes around in other languages too. I promise :)