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 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 :)