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

Raymond Espinoza
Raymond Espinoza
1,989 Points

swift types

how do you write out firstValue = 2 and secondValue = 4 to times to 8 in string interpolation ?

types.swift
// Enter your code below
let firstValue = 2
let secondValue = 4
let product = firstValue * secondValue 
let output = "\(product) 

2 Answers

Let me give you a more detailed reply. See below code.

let firstValue = 2
let secondValue = 4
let result = firstValue * secondValue

print("the result of your multiplication is \(result)")

first 3 lines is the calculation. What I additionally did in the last line is to print the result variable. When you have worked with XCode before, you know that this print("...") is used to write the text in brackets into the console. The last line also contains the string interpolation. By using...

\(VariableGoesHere)

...I can simply insert the value stored in a variable into the string.

Does this make any sense to you? :)

You need to add " after (product) in order to finish the string statement

Raymond Espinoza
Raymond Espinoza
1,989 Points

let firstValue = 2 let secondValue = 4 let product = firstValue * secondValue let output = "(product)" says format of your output doesnt match requirments ? How do i compute the product and print out the product in a formatted string?The string should read: "The product of 2 times 4 is 8".