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 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!