Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
I am not a novice programmer by any means. The idea of combining something like "The product of" into an interpolated S
.....String is not well explained. I am trying to add the words without making that phrase a variable of its own. Please elaborate on how to do this. Thanks.....
// Enter your code below let firstValue = 20 let secondValue = 30 let product = firstValue * secondValue let output = "\("The product of "), \(firstValue), \("times"), \(secondValue), \("is"), \(product)"
Greg Kaleka39,016 Points
So "the product of" is just a mathematical term that means the result of multiplying two numbers together. The product of 5 and 2 is 10, for example. You already have the product of
secondValue stored in the constant
product, so no more work to do there.
Secondly - you're doing way too much work in your interpolated string. There's no need to surround everything with parens. Interpolated strings are cool - you just write what you want the sentence to say except where you want to stick in a programmatic value like a variable or a mathmatical operation. For example:
let explanation = "The product of 5 and 2 is \(5 * 2), for example." // this becomes "The product of 5 and 2 is 10, for example."
Neat, right? Let the computer do the math
So for this challenge you want to do basically the same thing, except 1. you want to use your
secondValue constants instead of hardcoding the numbers, and 2. You want to use the
product constant instead of doing the math inside the string interpolation.
Really, you're quite close with your code. You've just got some extra
\()s and commas and quote marks in there. A few strokes of the delete key and you'll have it.
Make sense? Let me know if you still can't figure it out!