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

The video did not go over computing products.

I guess my question is: how do I do this?

types.swift
// Enter your code below
let firstValue: Int = 3
let secondValue: Int = 12
let product = "firstValue * secondValue"
let output = "\(firstValue) \(secondValue) \(product)"

1 Answer

andren
andren
28,558 Points

The product part of your code is mostly correct, the math operation you have typed is as it should be but you have enclosed it in quotes which is wrong. quotes are only used when declaring a String, for any other type of value or expression you should not use quote marks.

Also product in this instance is just a somewhat complex way of saying "result of a multiplication operation", so the product of 2 * 3 for example is 6.

Another problem with your solution is that the output string is not formatted properly. Challenges are very picky about text output, your string needs to match the one requested exactly. The challenge wants the resulting string to look something like this:

"The product of 3 times 12 is 36"

Your output lacks all of the words around the numbers, which needs to be there.

Taking all of those fixes into account the resulting code will look like this:

let firstValue: Int = 3
let secondValue: Int = 12
let product = firstValue * secondValue
let output = "The product of \(firstValue) times \(secondValue) is \(product)"

So your code was quite close, you only made a couple of small mistakes.