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

J. Tigre
PRO
J. Tigre
Pro Student 2,845 Points

How to assign the String "The product of (firstValue) and (secondValue) is (product)" to a constatnt name output?

let firstValue: Int = 3 let secondValue: Int = 5

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

types.swift
// Enter your code below
let firstValue: Int = 3
let secondValue: Int = 5

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

1 Answer

Matthew Long
Matthew Long
28,379 Points

You're close, but there's a couple errors. You got the string interpolation part correct, which was the focus of the challenge. You however forgot to set the type; since you used the colon you must set it. If you don't want to explicitly set the type you don't need the colon. You also don't need to have the constant interpolatedProduct, just create the output constant that the challenge was asking for.

let firstValue: Int = 2
let secondValue: Int = 3
let product: Int = firstValue * secondValue

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

Also, it kind of defeats the purpose of having product if you're going to do the math yourself :wink: