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

Donte nall
Donte nall
1,961 Points

StringLiteralType

let firstValue: Int = 2000 let secondValue: Int = 100

let product: String = "firstValue * secondValue" let output: StringLiteralType = "The product of (product) is 200,000"

///lost

types.swift
// Enter your code below

let firstValue: Int = 2000
let secondValue: Int = 100

let product: String = "firstValue * secondValue"
let output: StringLiteralType = "The product of \(product) is 200,000"

1 Answer

Hi Donte,

Well done for giving the challenge a go, you are pretty close, there are a couple of bits that need to change. I will outline them and try to explain.

let product: String = "firstValue * secondValue"

This would create a literal String with the value "firstValue * secondValue" - this wouldn't be interpolated, nor would we be able to perform any mathematical calculations on it, what we need is an Int (as both firstValue and secondValue are of type Int), that is the first value multiplied by the second:

let product: Int = firstValue * secondValue

It looks like you have got a bit confused with the next line:

let output: StringLiteralType = "The product of \(product) is 200,000"

as StringLiteralType is not a valid type, instead we need to use String. You have done will with remembering how to use string interpolation but we need to be doing this on the firstValue and secondValue fields before the answer (product):

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

Here is the whole thing:

// Enter your code below

let firstValue: Int = 2000
let secondValue: Int = 100

let product: Int = firstValue * secondValue
let output: String = "The product of \(firstValue) times \(secondValue) is \(product)"

I hope this makes it clearer and more understandable.

KB :octopus: