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

Raphael Reiter
Raphael Reiter
6,820 Points

stuck 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 ! :/

types.swift
// 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
Richard Lu
20,185 Points

Hi 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
Raphael Reiter
6,820 Points

thanks Richard, that's a great help. I got it now :)