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 trialRaphael Reiter
6,820 Pointsstuck at challenge : code could not be compiled
I have tried everything i could think of...
let firstValue = 2 let secondValue = 4
let product = 2 * 4
let output = "(The product of) (firstValue) (times ) (secondValue ) (is ) (product )"
please help ! :/
// Enter your code below
let firstValue = 2
let secondValue = 4
let product = 2 * 4
let output = "\(The product of) \(2) \(times ) \(4 ) \(is ) \(8 )"
2 Answers
Richard Lu
20,185 PointsHi Raphael,
There are two things that are a bit off here. One is in regards to this line (String interpolation):
let output = "\(The product of) \(2) \(times ) \(4 ) \(is ) \(8 )"
Using \(The product of) means that you're using the value of a variable called 'The product of', and that causes the compiler to complain. What you really want is this:
let output = "The product of \(2) times \(4) is \(8)"
Now the compiler knows that "The product of", "times", and "is" are strings.
Another minor thing that should be edited would be this line:
let product = 2 * 4
This is definitely going to be the correct answer, but what you want to get use to is using variables/constants. The code below will guide you through that
// you assigned these 2 constants values
let firstValue = 2
let secondValue = 4
// you can use them like this
//2 * 4
let product = firstValue * secondValue
Hope I've helped! Happy coding :)
EDIT: 10.26.15
The challenge has been fixed, and you can now have your solution like this:
// Enter your code below
let firstValue: Int = 10
let secondValue: Int = 5
let product: Int = firstValue * secondValue
let output: String = "The product of \(firstValue) times \(secondValue) is \(product)"
Raphael Reiter
6,820 Pointsthanks Richard, that's a great help. I got it now :)