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

***Im having issues with interpolation problem...It wont accept my code....I run it in XCode and everything works fine..

By the code you can infer what the question is about...

let firstValue = 20

let secondValue = 30

let product = firstValue * secondValue

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

Please help!!!!

1 Answer

I think you're having a little bit of trouble with the idea of string interpolation! The beauty of interpolation is that we can blend variables and constants with strings and numbers. Let's see interpolation in action:

let numberOfApples = 6
let numberOfOranges = 7
var message = "I had an amazing harvest today! I picked up \(numberOfApples) apples and \(numberOfOranges) oranges. In total, I had \(numberOfApples + numberOfOranges) pieces of fruit!"

In interpolation, we use the

\()

to signify a variable, expression, constant, or anything like that. What you might want to do is use these ideas to come up with your own solution. One more example:

let firstMultiplier = 40
let secondMultiplier = 50
let answer = "\(firstMultiplier) times \(secondMultiplier) is \(firstMultiplier * secondMultiplier)"

I hope that helps you!