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

How would I write step 2? I am slightly lost confused with string and Int

how would I write that equation?

types.swift
// Enter your code below
let firstValue = 19
let secondValue = 26
let product = firstValue * secondValue
let output = "The product of 19 times 26 is 494"

1 Answer

Anjali Pasupathy
Anjali Pasupathy
28,883 Points

This challenge wants you to use string interpolation. String interpolation allows you to insert variables and constants into a string without having to worry about what type the variable or constant is. You do this by putting the symbols () where you want the variable or constant to be, and putting the variable or constant name inside the parentheses. Here's an example of string interpolation:

let theAnswer = 42
var foundTheQuestion = false
let interpolatedString = "The value stored in theAnswer is \(theAnswer). The value stored in foundTheQuestion is \(foundTheQuestion)."
/*
 interpolatedString looks like this:
     "The value stored in theAnswer is 42. The value stored in foundTheQuestion is false."
*/

This challenge asks you to store an interpolated string in output. Instead of directly writing "19", "26", and "494", the challenge wants you to put the constants that correspond to those values into the string using string interpolation (i.e., writing "(firstValue)", "(secondValue)", and "(product)" instead of "19", "26", and "494").

I hope this helps!

Thank you for your help, it's my first day ever to swift so that has still got me stuck!