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

Jericoe States
Jericoe States
3,262 Points

I don't understand how they're trying to make me write this answer. I watched this video like 10 times!!

It's obvious what the answer to my equation is, but it just sounds like they want me to re-write the same answer on a different line. It's saying, "Make sure you assign the value of the product to the output." or something close to it. But when I click the button to review my mistakes, the screen is either blank or I'll write:

let output = "(product) = (firstValue) * (secondValue)"

and it will have an arrow pointing to the multiplication sign. Wtf am I doing wrong that the video isn't telling me???

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

5 Answers

james south
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
james south
Front End Web Development Techdegree Graduate 33,271 Points

you need to construct exactly the string they are asking for, "the product of x times y is z". you are almost there, just remove the quotes around product, it isn't a string, and build the required string for output with string interpolation. don't forget the closing quotes.

Jericoe States
Jericoe States
3,262 Points

Right or wrong?

var output = "product = firstValue * secondValue"

or

let output = "product"

?? I don't really want the direct answer, I would like to understand it rather than getting the right answer but it seems so simple and I can't understand what I'm missing. Should I just rewatch the video for string interpolation? Lol

james south
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
james south
Front End Web Development Techdegree Graduate 33,271 Points

well you basically have string interpolation down in the first code you posted, the last line, it's just missing a close quote. it's just "words words words (myVariable) more words more words". this would insert the value in myVariable in the string. so product is going to be one number times another, no string involved, that's just another number, then all three go in the final variable, interpolated in the string they want.

Jericoe States
Jericoe States
3,262 Points

So when i interpolate the string, am I using numbers and letters, or just words? I just don't know how to state the variable for the answer. Or do you think you could give me an example of how you combine an interpolation with a literal string? Maybe because I'm not actually using Xcode, it seems more difficult? I'm on a windows pc...

Jericoe States
Jericoe States
3,262 Points

Or do I start off with "product" in the beginning of the string? if so, then it feels like I'm writing the answer twice. And if its right, I still don't understand why.. I even looked at examples on the internet and they make more sense than what I'm trying to do.

james south
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
james south
Front End Web Development Techdegree Graduate 33,271 Points

just saw this....fyi if you hit ampersand and start typing a person's username, you can 'page' them in your response and they will get an alert in TH. the answer string that goes in output needs to be exactly what the challenge asks for. to interp the strings, you are doing it right, backslash then variable in parens. the interpreter will see that and fill in the variable's value in the string. product is a * b, it is not a string, it's a number, just use the first two variables instead of a and b. in the answer string you have words like i wrote above, and where you need the value from the variable to appear, you put the backslash and variable name in (). if state = ohio, then "i don't live in \(state)" will become "i don't live in ohio".