# Programming in Swift: Fundamentals

Oct 19 2021 · Swift 5.5, iOS 15, Xcode 13

## Part 1: Core Concepts

### Episode complete

Play next episode

Next

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

#### Notes: 06. Challenge: Logical Operators

Update Notes: The student materials have been reviewed and are updated as of October 2021.

Heads up... You've reached locked video content where the transcript will be shown as obfuscated text.

Hey, it's time for your next challenge. You can find the challenge in the Challenge-Logical Operators page of the playground you've been using, or you can download a new one from the resources for this video. Open it up and try solving the challenge questions on your own. But then keep watching to compare what you've done with what I have. Good luck! (Upbeat Music) Challenge. Number one. So you've been provided with a constant named myAge below that's already been assigned a value. Feel free to change the value of this constant to match your actual age. My actual age is 42, so I'll leave it there. Now use that constant to create an if-else statement to print out "Teenager". If the value of my age is greater than or equal to 13, but less than or equal to 19. And to print out "Not a teenager!" if the value is outside that range. So I'm gonna leave that constant up to 42, but feel free to change it. If you wanna help me feel younger. Now I'm going to start constructing my if-else statement. I want to check that my age is greater than or equal to 13, and that my age is less than or equal to 19. (keyboard typing) And then if this is true, I want to print "Teenager". (keyboard typing) But if it's not true, I'll add an else clause here to print out, "Not a teenager." (keyboard typing) And clearly I am a teenager, no more. Tell me about it. On to challenge two. Create a constant named teenagerName and use a ternary conditional operator to set the value of teenagerName to your own name as a string. If the value of my age declared above is greater than or equal to 13, but less than or equal to 19 and set the value of "teenager" name to "Not me!" If the value is outside that range and then print out the value of teenagerName. Ooh, okay. So let's break that down a bit piece by piece. So first you need a constant. (Keyboard typing) Now, you know that a ternary conditional operative starts with an expression. In this case, the expression needs a check if my age is greater than or equal to 13, and that my age is less than or equal to 19. And if this is true, then return the string, "Chris." But if it's not true, then return the string, "Not me!" And then I simply print out the value of teenagerName. And once again, I am not a teenager, now that's it for this challenge. Next up, you'll finish off this part of the course by learning about a concept in Swift called optionals, which lets you deal with the case when you don't have any value at all. I'll see you there.