Learn

Often times, we find ourselves needing to insert values into a string. In these cases, we can use string interpolation.

In Swift, to insert a value into a string using string interpolation, we can write the value in parentheses, and write a backslash \ before the parentheses.

For example:

var albums = 17 print("Daniel Johnston made \(albums) studio albums.")

It will output:

Daniel Johnston made 17 studio albums.

Magic! đź”®

Instructions

1.

Inside String.swift, declare a variable called age and set it equal to your age.

2.

With age set up, use print() and string interpolation to output:

I am [age] years old.

Where [age] should be the value of the variable age.

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?