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

J. Tigre
PLUS
J. Tigre
Courses Plus 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,407 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: