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 2.0 Basics Swift Types Recap: Swift Types

Bill Bruno
Bill Bruno
2,058 Points

Help with your code challenge

For this code challenge, this is what I put. Works with Xcode but the code challenge says I am wrong. Please help me see what I am doing wrong and why does it work with Xcode?

let firstValue: Int = 20 let secondValue: Int = 24

let product = firstValue * secondValue let output = "("The product of ") (firstValue) ("times") (secondValue) ("is") (product)"

types.swift
// Enter your code below

let firstValue: Int = 20
let secondValue: Int = 24

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

4 Answers

Zachary Kaufman
Zachary Kaufman
1,463 Points

Don't have ("") around your words. I think that will get it to pass. Hope this helps!

Bill Bruno
Bill Bruno
2,058 Points

Thank you. I will try that. I would have thought Xcode would have took an error on that as well. All new learning experience. Thanks again.

Zachary Kaufman
Zachary Kaufman
1,463 Points

Had that been a real life problem you would have passed because you were correct in your syntax. The only reason it didn't pass in the grader is because he was teaching how to input variable values into strings so the grader was searching for (variableName) inside of a set of " instead it got your solution of ("") and (variableName) so it counted it wrong. Good job and good luck with your classes!

let firstValue: Int = 20 let secondValue: Int = 24

let product = firstValue * secondValue

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

Grant Thomas
Grant Thomas
13,705 Points

It looks like you're using the interpolation syntax wrong. You only want to interpolate your two constants. Not the entire string (Or strings in between) Try this:

let firstValue: Int = 20
let secondValue: Int = 24

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