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 2.0 Basics Swift Types Recap: Swift Types

I'm not quite understanding this question. How do I create a string that reads a multiplication problem?

Please read my code and let me know. Thanks!

3 Answers

William Li
PLUS
William Li
Courses Plus Student 26,867 Points

Hi Nisa. Looks like you're having trouble with part 2 of 2 in this code challenge. Let me break it down for you.

Step 1: Declare a constant named product and assign the result of multiplying firstValue and secondValue together. (To multiply two values, a and b, we write a * b).

This 1st step is easy.

let product = firstValue * secondValue  // multiply 2 constants to get its product

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.

The description is lengthy, but the key here is this example String "The product of 2 times 4 is 8". All you need to do is replace 2, 4, and 8 from this String with firstValue, secondValue, product using String interpolation, respectively; and don't forget to assign the String to a new constant named output

The final code should look sth like the following.

// Enter your code below
let firstValue = 2
let secondValue = 4
let product = firstValue * secondValue  // multiply 2 constants to get its product

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

Hope it helps.

Challenge Task 2 of 2

Using these values, we want to compute the product and print out the product in a formatted string.

Step 1: Declare a constant named product and assign the result of multiplying firstValue and secondValue together. (To multiply two values, a and b, we write a * b).

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.

let firstValue = 248
let secondValue = 428
let product = firstValue * secondValue  // multiply 2 constants to get its product

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

'''

Challenge Task 1 of 2

For this challenge, let's pretend we're building a calculator that outputs a string with the result of a math operation.

Start by declaring two constants, firstValue and secondValue and to both of them assign some integer values. (Try and keep the values within a sensible range. Extremely high values will time out the challenge editor).

let firstValue = 248
let secondValue = 428
let product = firstValue * secondValue  // multiply 2 constants to get its product