This practice will be retired on May 31, 2020.
Solution: A Swift Biography1:46 with Pasan Premaratne
Your goal was to write a program that creates a mini biography about yourself. 0:00 So here's my solution. 0:04 Now yours doesn't need to be the exact same code as mine 0:06 as long as you end up with that final result. 0:09 So we start off by creating a constant and 0:12 assigning a string containing my name to constant named name. 0:15 So, remember again, the syntax to create a constant is we start with the keyword let, 0:20 and then we give the constant a name. 0:24 Then to assign something to that constant, 0:26 we have an equal sign followed by the value. 0:28 Now, you may have put a variable in here, and that's okay. 0:31 You still get the end result. 0:34 But remember we're looking for constants because Swift prefers constants, and 0:36 we'll learn more about why as we learn more Swift. 0:41 Next we do the same thing but this time we create a constant named age, and 0:45 we give it a numerical value, this is an integer. 0:49 Again then we have a city constant, and a string. 0:53 And then a country constant and then another string. 0:56 Now the important part here is we then use these constants containing our data and 1:00 string interpolation. 1:05 We use those tools to put together our final string. 1:06 So here it says, hi, 1:10 my name is, and then using string interpolation I pass in my name. 1:11 The syntax here is a backward slash and 1:14 then within parentheses we put the constant in there. 1:17 So in that way we put name, age, city, and country. 1:20 Now this might be something new to you, 1:25 but you'll notice here that I can mix types here. 1:27 So I can pass in using string interpolation and age value, 1:29 which is an integer, but as you can see in the results area, 1:33 the printed statement has a string containing the 28 years old value. 1:36 Okay, I hope you got some good practicing. 1:42 On to the next exercise. 1:44
You need to sign up for Treehouse in order to download course files.Sign up