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 2.0 Basics Swift Types Recap: Swift Types

HOW it will work

Using string interpolation, create a string literal that describes the operation we just performed. For example, given the following values for firstValue, secondValue and product respectively: 2, 4, 8. The string should read: "The product of 2 times 4 is 8". Assign this string to a constant named output.

// Enter your code below
let firstValue = 2
let secondValue = 4
let product = firstValue * secondValue
let output = "\("The product of ") + \(firstValue) + \(" times ") + \(secondValue) + \(" is ") + \(product)"

1 Answer

Hi Ravu! What you've done in your output variable is essentially an attempt at what string interpolation saves us from -- unneccessary concatenations (and more).

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

What you've tried reminds me of this:

let output = "The product of " + firstValue + " times " + secondValue + " is " + product."

I'll assume you have some previous programming experience, because that's what most of us would be used to (or worse).

With Swift's string interpolation, there's no need (in most cases) for those concatenation operators. The interpreter will search through your string to look for the special characters () similar to how it would do a comment, or escaped character.

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