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.
code challenge recap swift types step 2
Having issues understanding step 2 of swift recap types, any help would be greatly appreciated
// Enter your code below let firstValue = 2 let secondValue = 4 let product = firstValue * secondValue let output = "The product of 2 times 4, \(8)"
Jennifer NordellTreehouse Teacher
Hi there! Your code will generate no errors in Xcode so it may be difficult to tell why exactly this is failing the challenge. The problem is in your
output variable. You are hard-coding in the results. We need the output to reflect the values stored in
secondValue. Right now, those are set by the challenge and so they are hard-coded values. But imagine that you're developing some sort of calculator application. You would want those values to change to reflect what the user wants the first value and second value to be. Maybe this time they did put in 2 and 4. But maybe next time they'll put in 30 and 20. There's no way to know. Users are highly unpredictable.
So I'm going to give a hint here. You do need to use string interpolation but you need to print out the values stored in those variables. We do this with a backslash and a parentheses. It tells swift to put the value stored in that variable at that spot in the string.
var name = "Chris" print("Hi there, \(name)")
You might try this in Xcode. You'll see that what prints to the console is "Hi there, Chris". I think you can get it with these hints, but let me know if you're still stuck!