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.

iOS Swift Basics Swift Types Recap: Swift Types

Kavita Bargota
Kavita Bargota
2,741 Points

please could someone help me with the last question ?

need help!

types.swift
// Enter your code below
let firstValue: Int = 24
let secondValue: Int = 15

let product: Int = a * b
let output = "\(2) \(4) \(8)"

1 Answer

First you must declare a constant named product which should be the result for firstValue * secondValue right?

let product = firstValue * secondValue

Step 2: Using string interpolation, create a string literal that describes the operation we just performed. For example, given the following values for firstValue, secondValue and product respectively: 2, 4, 8. The string should read: "The product of 2 times 4 is 8". Assign this string to a constant named output.

Alright, so you now you have the make a string literal which explains the math you just did (using string interpolation*) and assign it to a constant named output

string interpolation is

\(anyConstant)

// i.e.

\(firstValue)

inside a string literal - which is text inside quotes i.e. let someString = "this is a string literal"

so the answer would be as follows:

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

Happy coding!

Kavita Bargota
Kavita Bargota
2,741 Points

Hi Marcus,

thank you very much.

I only understood with your help, thanks :)