Make Your Own iPhone Game! | Seth Bollenbecker | Skillshare
Play Speed
  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x
15 Lessons (1h 44m)
    • 1. Course Intro

      1:24
    • 2. Playground Intro

      7:23
    • 3. Constants

      8:04
    • 4. Data Types

      12:10
    • 5. Inference vs Annotation

      3:19
    • 6. Operator Basics

      6:03
    • 7. Comparisons

      7:08
    • 8. Conditions

      10:27
    • 9. Multiple Conditions

      4:38
    • 10. Part 1: Program Creation

      6:40
    • 11. Part 2: Assistant File

      5:07
    • 12. Part 3: Foundation Code

      11:20
    • 13. Part 4: User Input

      6:58
    • 14. Part 5: Game Looping

      8:14
    • 15. Part 6: Final Project Demo

      4:39

About This Class

b406d8af

Do you want to become the next millionaire Flappy Bird creator? You're in the right place - welcome to the complete iOS Swift Development course! Anyone, even those who have never coded before, are encouraged to take the challenge and get to work creating their first iOS app. Go from not knowing the difference between ] and } within a few lessons and start making millions off of the next big idea!

Transcripts

1. Course Intro: Yes. Oh, hi there. I didn't even see year. I've been too busy playing that new hit game on my phone right now. Have you ever thought to yourself like, man, I wish I could create the next Flappy bird or angry birds Or, you know, the next few Jap that's gonna make me a $1,000,000 just like they did. I thought the same thing when I started developing. And you know what? I've learned a time I am may not be a millionaire right now, but I've definitely made some money off the APP store, and you can, too. That's right. With just a few classes about coding, you can create your own APS and do whatever you want. So in this introductory course, I'm gonna show you a little bit around X code, the program that you're going to be using and swift the language that you're going to be using the code, all of these APS. And you know what? By the end of this, you're gonna have an app or a number game that you're going to be able to run on your computer, and soon after that, follow up with my other classes and you'll be able to find out exactly what it takes to make that next new hit app on your iPhone. I look forward to seeing you guys in the class. Thanks for checking me out. Good luck. 2. Playground Intro: Hi there, everyone. And welcome to the first swift slash X code slash introduction video of this course. So today we're going Teoh, take some time and take a look at X code, Um, and actually work our way around and kind of figure out some of the basics. So before you begin, you need to have X code downloaded on your computer. Um, if you're on your Mac right now, which you must be to actually develop, you are going to come down to the APP store or search for it and your search bar, and then you're just going to search for X scared. Once it pulls up, you'll see it over here. Um, it is Theis XKR Developer essentials and your should stay, download or install or something like that here. So you're going to go ahead download that it's a fairly large file. At the time of this video, it's 4.41 gigabytes. It's always getting larger, and so it will take a while to download. We're gonna go ahead and quit out of that. And when you open up X scared for the first time, you'll see a screen similar to mine. Um over here on the sidebar. We have some recently open APS, so go ahead and ignore that. For now, you probably will have an empty window over here. And the two most use features that we will be focusing on is get started with the playground and create a new X Code project. Now, since we're new at this and just starting to learn our way around X code were actually not going to be creating a new X Code project yet We're just going to beginning started with Playground. This is a little bit of an easier step in, and I'll show you exactly what the differences are in just a moment. So go ahead and click. Get started with a playground. Now you'll need to create a name for this first project that we're doing. Remember, this isn't actually your final project, So the name that you give it really doesn't matter. We're just gonna play around right now. All right? Now, if you look below it, you can select a platform for IOS OS X, which is Mac and T V. O s, which is the Apple TV. So just go ahead and click IOS and then click. Next, you'll see a place pop up where you can select where you actually want her project to save . Once again, this isn't your final project, so it really doesn't matter at this point and then click create. You'll see the project appear wherever you saved it, and then you'll see this window pop up. So this is our playground. The reason it's named a playground is because we can kind of adjust the carrot to show exactly what we wanted. Teoh. And it runs right in this program. You will see a bit of code over here on the left, and then if you look across the screen on the right in this little sidebar, you'll actually see what our code has produced. Now Apple gives us a little starting code so that we can know that this is actually working . As you can see, there's a little bit of code here on the left, and we'll learn more about all of what these things are and a future tutorial. But you can see that the hello comma playground is exactly represented over here on the right hand side of the screen. So what we're gonna do is just go ahead and edit that so that we can show that exactly what we type over here on the left is going to appear on the right. So we'll just delete that and we'll put hello world with an exclamation point. If you notice on the right hand side of the screen automatically and instantaneously, the code has been updated. Teoh show exactly what we had just typed. So this is something really nice about playground that allows us to type the code out and then have it automatically show up on the right hand side later on, when we get into actually developing, APS will have plenty of time to write our code, and then we'll have to run it in a separate application that actually makes it run rather than just having it continuously run right alongside what we're typing. So that's it for this basic tutorial. Go ahead and play around. You can take whatever you want, Teoh in the code. And actually, I encourage you to play around with what Apple has typed here so that you can actually, um, end up breaking what they have done. Because the easiest way to learn how coding works is to break it or to have something not go right, because you learn much more easily what has to be right and what has to be set in stone for a program toe actually work. One more thing I wanted to go over with you today is, um it refers to these little forward slashes at the beginning up here. So what that does is it tells x scared our project that it that we want to ignore whatever is being displayed in that line. So what we're going to Dio is just hit the enter key twice, and then we're going to put two more of those forward slashes. As you can see, when I type them, they turn green. And that's a key indicator. Thad, this is just a note where you're creating for our code. For example, if you were typing up this project and you wanted to know that this part of the string just did a certain function, we could put that in a note so that we wouldn't have to search through the code and try to figure out what that section did. So for this now we'll put this string produces Hello world on the spring, if you take note over here on the right hand side, nothing actually appeared. But on the left hand side, we have our note that can actually be seen behind the scenes. So when we're publishing projects, this string right here won't actually show up to the people that are actually viewing your app. However, they will not You know exactly what you were typing up. That's all that I wanted to go over with you today in this first tutorial. So I hope you guys enjoyed it and keep watching. We'll create our first app soon enough. 3. Constants: hi, everyone. And welcome back to the next tutorial for X Code and Swift. Today we're going to be talking about variables and constants. They both go hand in hand, so we need to talk about them together. And they're pretty straightforward, considering the name of each of them kind of corresponds to what they do and how they act. So what we need to do is go ahead and open up your, um, playground file, and it will just be the regular apple pre filled information. Just go ahead and delete this road right here. We just want the import. You like it. You can delete their note if you want to as well, but just have that important You. I kid up at the top. That's what tells the program to import. Everything that Apple has is a framework in the background. So we're going to go ahead and talk about these two variables and constants, and we'll just start with variables. So a variable is a value that you might use in your program, and it could be changed so kind of go back goes back to the hole. Variable name of it. It's implied that you will be changing it or that it will be changed in your courts of your program. So go ahead, type bar, which is short for variable. And if you press the space bar, it should show up as being pink. Because this is, you know, something that Apple and the X Code recognizes as being a natural command. So we're going to go ahead and put in Hvar name just to give our variable name and then space and then equals and we're going to say, Ah, the variable name. It doesn't matter what you put here. So you put John Smith, you put your own name, but this is just to tell the program that we're assigning the variable name to equal John Smith. And so if we space down and let's say we put name right below it if we just typed the variable name from up above, um, you see how he named it name? If we re type that again in our output, it will automatically put what we have assigned the variable too, right below it. So, um, it will actually use whatever name of the variable we put. So let's say we named this date. Instead. If you look down here after the product finish running, there's an air because it doesn't recognize this variable name. This means nothing to x cowered until you assign it to an actual variable. So we'll go ahead and change that back to name. And then down here, where we have name on the second line, Um, let's put equals, um Romeo. So, as you can see, if you look at the right hand side of our screen over here, we have named the Are. We have assigned the variable name John Smith in this first row. And then in the second row, we named it or we assigned it Romeo instead. So basically it replaced this John Smith. The reason that we did this using a variable is because we wanted Exco to know exactly how our variable was going to react. So we wanted to let X could know that it was going to be replaced or changed. And it was the next the very next line. We changed name to Romeo. No notice. The ex code program already knows that this is a variable. That name is a variable. So when we type it a second time. We don't need to say that it's a variable. We could, um but then we would get a return oven air. If you see over here to the left hand side. This constitutes that there's some kind of air. If we click on it, it will let us know what the air is. And it says invalid redecoration of name. That means we have a variable called name equal to John Smith here and a variable called name equal to Romeo here. It doesn't really make sense because you can't have something can be equal to two things at once. So whenever we are reusing or changing our variable, we just put the variable. We just put name equals Romeo, and the variable name has changed to Romeo. Now the other, um, piece of this program that we can use is ah, constant. So if we look down, um, just enter a couple of lines to get a fresh start, and we're actually going to put let instead of our this time. So let let's x Code know that we're going to be using a constant. This is a string or value. That X code knows we don't intend to change. So if we say let, um, name two, we're going to give this a different name. This constant. Um, let name to equal, uh, Mike Hill. Um, you can see that the variable still shows up on this right hand side. Um, excuse me. The constant still shows up on this right hand side, Mike Hill. Except this is letting X coat know that we're not changing this variable later on. So if we go ahead and enter and we try just what we did above, um, with name two, you'll see it turns blue because it recognizes it. My kill appears on the right hand side of the screen as our output. However, if we try to set equal to, um, Romeo like we did in the 1st 1 it's going to come back and give us an air the air says cannot assign value. Name, too, is a let constant. So if we look up above, um, this let statement Latin name two equals my kill. That is letting X code note that this variable won't be changed. And in the very next line we chart. We tried to change that constant. So therefore X code gives us back in air now, you might be asking, Why do we even need this at all? Like, why wouldn't we just use variables for all of our programming? And there's a pretty simple answer to that. If we used variables all the time, it's just more than X curd and swift have to think about. And it's more that we have to think about in terms of things that could be changed in things that can't. So if there's going to be a value in your program that you know you never need to change, then you should assign it a constant or a let value, because that will tell you later on, when you've typed thousands of lines of code and you try to change that variable that Hey, wait, I didn't need to change this in the first place, so obviously I need to reassess either the type of variable slash constant. Or maybe I'm changing something that I shouldn't have, and that's the basics for variables and constants. I hope you guys enjoyed 4. Data Types: Hi, everyone. And welcome to the next swift slash X code tutorial. Today, we're going to be going over data types. We have variables. We have bowling's. We have floats. We have, um integers. So there's a lot of different data types that we can play around with and swift. And so we need to know the difference is between them and when to use them and when not to use them. So let's go ahead and jump in with something that you probably are already familiar with from our previous video. And that is variables. So go ahead and type of our name. And we've just told x code that we're going to have a data type of a variable, which means this May or the should change in the future. And its name is name. Um And then we're gonna go ahead and just type in name equals, Ah, Sam Smith down here below it. So what we've done is we've told Exco that we're going to have a variable called name, and that name is equal to same Smith. But as you can see, there's an air over here, um, with ex curd saying that the type annotation is missing and your pattern or your code. So what that means is Exco doesn't know what type of variable that says so. We need to specify that in this case. So if we go right here behind name and we type it colon and then type string, um, that error should disappear. And there it goes. You can see that we have Sam Smith over here on the right hand side of the screen. And then over here on the left, our air has disappeared. So what string is is it saying that we're going to have a string of text? That's the best way to remember exactly how this variable is specified. String is a string of text. So any time you're using tax, do you want to use the data type of strength? So that's about it For that, Um, we're actually going Teoh hit the enter key twice and create another variable. Um, and we'll just call it a date. And then, um, we're going. Teoh actually assigned this one as an integer instead of a string. So an integer if you're familiar with your math class, is any number that is round off. So it could be 41 b 86. It could be negative 1000 but it can't be anything with a decimal. Decimals or fractions are not integers, so we're just looking for whole numbers in real numbers. That's what defines an integer so we'll just go down to the next sign and tight date equals 2016 for example. And there you go, Um, you can see and the right hand side over here we have 2016 listed as the variable. So remember, when you have a string, it's going to be a string of text. And when you have a date or when you have an integer, rather it is going to be a whole rial number. Um, no decimals or anything like that. So what we can do is if we hit enter a couple of times. If we want to recall these at any time, we can just type the men so name you can see on the right hand side will return. Sam Smith and date you can see on the right hand side will return 2016. They keep their values throughout our entire program so long as we don't change anything about them. So we're gonna go ahead and delete that. And then, um, there is a little fail safe, um, in x scared. And, sir, I'm going to share you just a little bit about that. It's called type safety. So let's say we have a variable and it's called name, and we've assigned it to be a string like a string of text. However, if we try to change that variable Teoh, let's say and then a number or an integer later in our program. So let's go ahead and type that up now name, and then we try to change it. Teoh 2017. Instead of being 2016 we're going to get an air over here from X code saying Cannot assign value of type integer to type string. As you can see, our variable name is a type string up here, and this 2017 is actually an integer. So we're going to get an air. I'll show you how it works in the other direction as well. If we have, or if we take our date variable and we try to assign it, um, a string of text. It's like Sam Smith. We should get an air with that one as well, saying that you can't assign a value of type string, which is what we have typed in here Sam Smith to type integer because remember, date we told it to be an integer, so that returns a little bit of a problem. So that's it for string and variables. Let's move on to another type of number. Um, if you recall intruder has to be, um, a entire whole number. You can't have fractions or decimals, but in many cases, you need to use fractions and decimals. So we have a couple of other data types that could be used for that. We have, um, doubles and floats, so there's not really a whole lot of difference between double and float. What ends up happening is that float is actually less accurate than a double. So apple actually recommends that you use double for most cases. So I'm just gonna go ahead and show you Now, um, let's just put in far number, which is the name of our double variable. And we're just going Teoh, specify that it is a double right there down to the next line. We're going to put in number and cools and a sonnet a value so 12.856 we enter a couple of times and type in number. We're going to get 12.856 just because we use this data type of double now, if this was ent, remember that integers can Onley be whole numbers, not fractions or decimals. So we're going to get an error down here that says we can't sign a type of double to a type of introduce. So that's where we run into complications there as well. That's all. You should pretty much know about having, um, decimals and your program. If you want to know a little bit more about the differences between doubles and floats, you can find it on the Internet. But Apple recommends that you just stick to this type of using double as your preferred method of coating when you're working with decimals because it is more accurate now, the last thing that we're going to go over is actually called a bowling. You've probably seen this and plenty of different um, programs or locations around the world. Basically, a bullying is just a switch that says something is either true or something is fault. False. So what, We're going to dio eyes just type up bar again. Remember, we're always working with either variables or constants here, and most of these are gonna be variable because we will be changing them later in the program. So we're just gonna type in Hvar and type in open, um, and a sign it the type bull, which is short for bowling. So we're just going to go ahead and say that open is equal to true. And so over here in the feedback side, on the right hand side of our program, we knew were we that we know that the variable open is set to true right now. Um, so we're just going to go down here, and now we're going to work with the opposite side of the spectrum so we could do far, uh, closed. Cool. And since the bull or bowling for openess true, we're just going to say that the bowling for closed is equal to false, so that's going to return our faults. Now there is no maybe or some wet or perhaps or anything in the middle with bowling's. It's either true or its faults and there's no room toe have kind of either or in the, um in the middle. So we're going to go ahead, delete that The final little note that I wanted to tell you guys about, um is actually how to use your annotations or your, um signalling to x code of certain very variable types very wisely, because X codes also smart on its own. So if you think back, um, toe when we typed in far name string telling it that variable name is a string on, then actually assigned that variable to Sam Smith, this is the long form of that code. So we can also put in far name is equal to Sam Smith as well. Do you see the differences between this code one as much longer? It takes up two lines, takes a lot longer to type. So for simplicity and for X code being understand being or for utilizing X cared for all that. It's worth what all we need to dio is just type in Hvar name equal Sam Smith. We don't need to tell x code explicitly that this is going to be a string because we know and Exco dinners that because we type the variable, the name of the variable and equal to a string of tax that it is string Exco just knows this. We don't need to tell it. So whenever you're introducing your variables, let's say we have Baradei equals 2016. X Code already knows that the variable of date is an integer because we have a whole number without any fractions or decimals. It just cuts down on the time that it takes you to code and it cuts down on the lines that uses and it cuts down on, um, you actually having to put in more effort than it's worth for the program toe already. Know exactly what you mean. That's it for today, folks. I hope you guys enjoyed it. Thank you. 5. Inference vs Annotation: Hi, everyone. Welcome back. Um, I just wanted Teoh do a brief video about using type annotations. I know I went over it at the tail end very quickly of last video, but I just wanted Teoh, um, specify that there are two very different ways. Teoh show what a variable is an ex code and one is definitely preferred over the other. So I'm just going to go ahead, um, and type in a variable will call it name, and we'll set it equal. Teoh, Sam Smith. I'm also, uh, going Teoh. Put that down below. Um, create available, uh, name Teoh going to give it a string type and then say name Teoh. It's equal. Teoh Smith. Okay, so we have our two types of specificity are specifying exactly what type of variable we have here. We have inference, and we have annotation. So this top one is called the annotated foreign of specifying what your variable is. We're coming right out, and we're saying variable name, too is a string. Um and then name to the variable name is equal Teoh. And then we put our string. The 2nd 1 is actually called the inference type of variable and it is listed as variable. And then name. The name of our variable is equal Teoh. And then we have our string. So as you can see, um, kind of going along with what I said last time, it's easier for you to type out. It takes up less space, and it's just it just makes more sense to the program to use the inference type. And this is the type that I'm talking about down here on the bottom. So they both produced the same results, but its preferred that you use the second method. So going on from this point forward, whenever we're assigning variables into different groups or telling them whether they're a string or an integer or whatever, I'm actually going to be using the second method, and you should be too. So this is more of an instructional video just telling you that this top method is actually not preferred. So I'm going to go ahead and delete that this one right here is the one that you need to be focused on whenever you are creating variables or constants that you're going to use in your programs. That's it for this video. Just wanted to give you guys that quick clarification. Thanks for watching 6. Operator Basics: Hi, everyone, and welcome back to another swift extra tutorial. Today we're going to be talking about operators and really just the basics of those operators trying to get your introduced to them. So a lot of this is going to come back to your elementary math class, but we're going to be doing it using code now. So we're going to go ahead and type in a variable. We're just going to name it a just for the sake of simplicity on and we're going to set that variable equal to 12. So there's a lot that we can do with operators to manipulate our variable. We can say, Um, well, first of all, we know that a is 12 because if we just type A and that's all we wanted, obviously, over here in the right hand side, we would get the value of 12 because we haven't changed it. But considering we assigned it to a variable Ah, it means we probably are going to change it. So let's go ahead and do you a plus one. And as you can see over here on the right hand side, it returns 13 because we have a which is equal to 12 plus one equals 13. The same thing. If we do a plus two, it will return 14. Now I can even use the variables in the operations multiple times so we can do a plus a 12 plus 12 and we get the result of 24 over here on the right hand side of the screen. So as you can see, these variables can be manipulated in quite a few different ways. Um, let's go ahead and take this off the screen and we're going to a sign variable B, and we're going to say that it's equal to five. So now we have A and B, and we can do multiple things with those. We can add them together. Um, let's just be careful. They were get so a plus B is 17 Um, Dio a minus bi helps and end up with seven. We can multiply them together to get 60 and we can divide them Now. Keep in mind that when we're dividing these, it's taking an integer of 12 and an interpreter of five, and dividing those and producing an integer so 12 divided by five is actually much more precise. than just to. But remember, when we're using integers, we can't have fractions, and we can't have decibels. So that's all of the string that it can actually show up to this variable. Now we can do the same thing using strings as well, not just variable. So we could assign variable name one here equal Sam Smith and the variable name, too to be cooked. So if we hit enter a couple of times, um, we can actually say that another variable is going to be name or well, say both since we're implying that they're both together. Um, and we're actually going to use a little bit of math with our strings, which might be a little bit confusing, but you'll see how it turns out in just a second. So we have name one being Sam Smith name to being Tim Cook. And now, for this third variable of both, we're going to put in name one. You'll see that shares up green because it recognizes it from being used before, Um, then we're just going to use the addition symbol and put an actual string of text in here with the space bar and in another space just to create some space, Um, before and after the word and that will actually show up in our program. And then we're going to put another ad and put in the name to which is Tim Cook. So by inter down, you will see over here in our results, we actually have Sam Smith and Tim Cook exactly how we have it typed ever here but invariable form. So this is name one which is equal to Sam Smith. And then we're adding in the letters a space and in another space, and then we're adding on name to which is Tim Cook. So as you can see exactly what we put in here, even with the addition marks and our string, it comes out to you. Sam Smith and Tim Cook Exactly the results that we wanted. You can play around with this. Obviously, if you tried Teoh ad, um, strings together, it isn't going toe work, but you can add numbers. You can divide numbers, you can multiply numbers. You can, you know, add and subtract. You can get all of the operators on. Then you can play around with actually putting strings together. Not actually adding them but adding him into another variable, which creates a full stream. That's it for today. I hope you enjoyed watching and thanks for watching. 7. Comparisons: everyone. And welcome back to our next installment of the swift X Code coding tutorial. Today we're going to be talking about comparison operators. So, like in the last video, if you recall, um, we can have operators such as a the variable A equals one, and then we put a plus a, and we should get to return value of two. And yet we do right over here on the side. So those were just some basic functions that we went over last time. This time we're going to be doing some comparisons, so we're going to be saying variable A is equal to one. Um, variable B is equal to two. Now, let's compare these numbers. So if we want to ask our program if variable A is less than variable B, which we know it is. But we wanted Teoh asked our program this because maybe we've manipulated it in our, um coating. So we just say a less than be. And this is kind of like asking ex code a question. And if you look over here on the right hand side, it returns a bowling. If you haven't watched the video about data types, you should go ahead and watch that now. But this is going to return a true answer or false answer. One or the other based on, um what data we're looking for. So a, which is one is less than B, which is to is actually true. So we will get the answer true over here, to the side. If we did the opposite A and ask if it is greater than be, then we will see that the answer false is returned over here on the right hand side of the screen. So this is just a easy way to determine, um, what your values are if they've been changed, if they fit certain parameters and all of that. So it really helps to be able Teoh, um, ask these questions of X scared. Now, we can also add in another, um, another symbol, and we can put the equal sign right there. So this is asking ex cared whether a is equal to or less than be which, if we the enter key you'll see is true because one is indeed last Stan or equal to two. Um, if we change a up here to to then our a is less than or equal to be stays true because two is equal to two. Um, so this just adds another layer of that operator instead of putting the line down below it , which we don't have on computers. We just put the equal sign after the greater than or less and signs. So if we were able Teoh, take this away. Um, now A and B are equal to to a is not less than be anymore. It's equal to it. So that's how that comes out. Next, we can try this with strings as well. So if we have a variable name and we put Sam Smith and then we ask, um is name equal to and let me point out now that I'm actually putting two equals marks to show that we're asking a question of whether this string is equal to something else. If we only put one then that's telling it, we want it to be something else. So this is just asking a question rather than giving a command whenever you put two equals marks, so put name equals equals Sam Smith, and then you'll see over here on the right hand side, we get the true because I our name the variable name is set to Sam Smith and we asked if it was set to same Smith. Now, if we set our name Teoh John Smith, and said and ask if that name is equal to Sam Smith, then obviously we're going Teoh, get the return of faults because these names don't match up. Our variable name is set to John Smith and we're asking if our variable name is equal to Sam Smith and they're not, so it will turn return faults. Now, if you take a look at this, um, if we are asking and receiving the right answer and we get a true, um let's say we change one of the letters to lower case. So, John, will this change the beginning of that toe Lower case Notice that this becomes false over here. That's because X code reads thes strings as upper and lower case it. It needs to be exact. So the amount of space is the upper and lower case. Any numbers you have in there, the exact string has to match what is being produced when you name the variable or changes , so just keep that in mind that if you accidentally miss ah, keystroke or forget to hit shift, it will mess up your code Sometimes if you don't stay on top of it. Now, one more thing that I wanted to go ever is, um, the not operator. So this is a signing the variable name ah to equal John Smith. And then we're asking if name our variable is indeed equal to John Smith and it returns true. Now what happens if we change the second equal sign or the first equal sign rather to a exclamation point? Then you'll see over here on the right hand side, it actually changed toe false. And that's because this is a not operator. So adding in this exclamation point before the equal sign is asking if name is not equal to John Smith and it actually is false. This is like a double negative here. So if we changed this to John Snow instead, then it will become true. Because indeed the name is not Jon Snow. It is actually John Smith. So then this operator will give the outcome of true for the bowling. That's it for today, guys. Thank you for watching. And I hope you enjoyed the video 8. Conditions: Hi there, everyone. And welcome back today, we're going to be going over. Um, what are called conditional statements of that saying, um if this than do that. Or, um, if this is true or if this is true or if this is true, then do separate actions for each of them. I'll get into it a little bit and you explaining, or you'll figure out exactly what I'm talking about. It's a little bit confusing to explain, but when I share you, it'll come to you. So first, let's start off with creating two variables. We're going to create a variable called, um type and we're going Teoh, give it on the variable type of string and we're also going Teoh, use the variable, um, person and we're going to assign that, um cool. All right, so what we're going to dio is we're going to create an if statement using the variables that we specified above. We have a variable named type that is a string, but it doesn't have a value in it yet, and then we have a variable called person, which has a value of cool. So let's go ahead and type our if statement this is going to be the format for all the if statement. So just take a note of the format while we're doing this without all of the variables that we add in and everything because the formats going to stay the same but are variables might change from program to program. So I'm just going to type in If, um and we're going to reference the person variable eso were just saying toe X scared. Hey, if something is up with person, that's what this little bit of code, um, tells x scared. And we're going to be using those conditional, um, statements that we had earlier and using the double equal sign because we have a string and we want to know if the string of person is equal to cool. If it is, we're going to put whatever we want the program to dio right in between these brackets that were automatically placed. Let me go back and delete thes, and I'll show you, um, again, what happened? So if we press or if we space bar next to the cool inclusion and, um, quotation marks, we're going to put the little curly bracket um, it should be beside the P keyboard on the keyboard if you hold down shift. Um, your keyboard might be a little bit different, so that may not be 100% right. But on my Mac book right now, that's where the key is. Just searched around for it for a minute. And then what, You hit return right after you put that it automatically closes off your brackets so that you don't get confused or you don't close them up. It's just a nice little future of X code where they kind of finish up your code for you, and then you can see exactly what parameters you're working within. So what we want to do is, um, actually change tight the variable, um, to Nice. So as you can see what this if statement is asking, is it saying if our variable person is equal to or if it matches, cool the string, which it does, then perform this action type are variable from up here? That is a string. We're going to set it equal to nice. If we had assign this value earlier on, um, the value type doesn't actually have any variable within it. So if we come right below here. And we want Teoh. Um, just see what type is equal to notice. Over here on the right hand side of the screen, nothing is showing up. The next thing that we're going Teoh go ever is We're actually going Teoh producing if, um or else if statement, uh, that actually signifies multiple outcomes. So obviously, with our if person equals cool, then we change our type String Teoh. Nice. But what if we want more outcomes than that? If you move your cursor right here after that last bracket that the program automatically put in for you and then you hit, um, the space bar, you can type else If, um to signify that we're going Teoh be adding in another condition to this statement so you can type else if and then use person again. Um, and we're actually going to ask, um, if they are un cool and then we're going to do the same space and same bracket that we did before and then just hit the enter key once again. Then we're going Teoh, type out the action that we want performed. If the person is the person, variable is equal to this uncool string, not the cool string. This is if the only reason it would get down here to this LCF statement is if the 1st 1 failed. So if it if the program asked if the person variable was equal to cool. Um and the answer was no within the program. Then it would just skip doing whatever is inside down here underneath for the condition. And it would skip down here to the else f and go through the next part and say, if the person is equal Teoh un cool. What do we want it to do? We can change the tight variable. Teoh. Ah, whoa! Or what have we wanted to do there in terms of changing the text of this variable type string up here? So that gives us two conditions. But we can't end on, um and if or else if, um without having some kind of statement to catch all the rest of the possibilities. So how we end this is actually using an else statement. So what this does is it leaves us the option. Teoh, have a catch. All if the program goes through your first if statement, If person if the person string is equal to cool than it does that if the person string is equal to uncle, it does this. However, if it's not equal to any of these listed above it, we have an an else statement that can say, Well, if it's not equal to those two than all of them kind of fall into this category. So we don't need to say, um, we don't need any conditions. They would just say else because this is everything else that isn't specified up above and we can just put type uh is equal to, um wow. And there you go. You've got a conditional statement that has three different outcomes. So as you can see, our variable person is equal to cool. It's going to go through this program. Say, if here, if the variable person is equal to cool and it's going to say yes, it actually is, and it's going Teoh, perform this action, changing the variable type two nice, the string of it. However, if we change this variable Teoh un cool instead, then the program is going to go through, and if you notice here on the right hand side um, our outcome actually changed because the program went through and it said, If the person is equal to cool and it's not, then it's not going to do whatever is in this. If statement, it's going to skip to the next line, and it's going to see that the person is equal to un cool. So it's going Teoh, change the variable type, um, up here the string to whoa instead. And you can see that on the right hand side. Now, if we change this variable Teoh, anything that isn't either cool or uncool, we just change it to phone something that is unrelated. You'll see down here that the else statement kicks in. It is that catch all that gets anything that isn't part of the 1st 2 statements and you can actually have more else of statements. You could add 10 down here and then still haven't else, and it would catch everything else. Um, and as you can see this while now shows up on the right hand side of the screen because we have changed the string Type two wow instead and it's caught that because this variable person is not equal to phone or it's not equal to cool. And it's not equal to un cool. It's something else. So it produces. Wow. And that's it for this tutorial. I hope you guys really enjoyed this. We're really getting along and will be parting starting our part, our project soon. So I really look forward to that. Thank you guys for watching. 9. Multiple Conditions: Hi, everyone. And welcome back to another swift slash X skirt tutorial. Today we're going to be going over what it means to be evaluating multiple conditions. So in the last video, we were just assessing whether something was true or false or whether equaled something based on our if statements. So what we're going to do in this video is assess how we can do that if we have multiple variables that we need Teoh, look at and evaluate. So we're going to go ahead with our blank playground project and create a variable called today and we're just going to give it the type strength. We're not gonna sign anything to it right now. Um, we're just going to leave it open because later on will be assigning values to the next thing we're going to do is create two of the values or to the variables rather that we need to manipulate. So we're going to create a very ball called Mourning and go ahead and set it to true, just to give it a value. And we're going to go ahead and create a variable called night. And we'll also set that one too true. So Here's where the multiple conditions come in. We're going to create an if statement like we did in the last video. But instead of Onley having one of our variables to assess here, we're actually going Teoh, put a double Amper stand that's going Teoh, Tell it that we are evaluating multiple variables. Instead, we're going to go ahead and type night. So this statement, um, is set up to accept two variables. You could have mawr if you wanted. Um, but for this purpose, we're only gonna use the two variables that we have a boat if we click the enter button, you know, automatically and the curly bracket for us. And as you can see, um, our variable for morning is the bowling of set to true in the variable of night. The bowling has also set that true. This if statement without needing to say true or false or anything in that just implies that we're asking if the variable morning and the variable night are both set to true. Do whatever is in the curly brackets. So we're just going to say today that unassigned variable and we're going Teoh said it. Teoh. Morning. So now we get the output of morning down here because we have both of these set to true. Now, if we change one of these two false you'll see that morning will disappear because both of them will not be true according to the statement right here. So if you look over here on the right hand side, morning is no longer an output because morning and night are not true. One is true and one is false. However, um, we can actually do what is called a not operator here, just like we did with equal signs so we can put an exclamation point in front of one of our variables to stay. This is not, um, true. So if you're reading this in code, we're asking the program if morning is true, since there is no not symbol in front of it. And if night is not true or false. So if we run this than it actually does succeed because morning is true and nineties faults and today is set to morning once again if you look over here on the right hand side morning now shows up. So for using this exclamation point, it could be pretty powerful. Um, this is how we say not or false in these multiple conditions. Statements. That's it for this video. Guys. I hope you enjoyed it. We're getting closer and closer to our project, so I'm looking forward to it. Thanks for watching. 10. Part 1: Program Creation: I, everyone and welcome to the first actual project Completion guide. So what we're going to do in the video today is just kind of show you how to get set up and get your files ready in order before we start actually coating your final project. One thing I wanted to mention before we begin is this project has a 1,000,000 open doors in it. So while we might be creating a program that has to do with number guessing, I encourage you to follow this tutorial all the way through. And then at the very end, take all that knowledge that you have now and give it your own spin. So add different text or add different ways that someone could guess the numbers. But all of this will make a lot more sense once we get done with the project. But if you're continuously thinking of ways that you could change something or alter it to make this project to your own, that would be great, because at the end, what I would love to see you upload is something of your own that no one else has made. And you put a spin or preferably a large man on something that we've completed. So let's go ahead and get started. You're gonna want to open up X code to the main screen here, and this time we're actually going to hit, create a new project. We're not working in the playground this time because of something really important. And that's that. The playground is great for seeing your code, um, completely live when you're working on it. The only problem is it doesn't allow for user input. So while we're coding, once we run our program, it won't let us type in our numbers that we're going to use for a number guessing game. So we're going to create a new project, and then you'll be presented with this new window from, uh, ex code. And you've never seen this part before if you haven't explored the program. But I know you guys really want to get into IOS Development. Ah, but we're actually going to go down here Teoh os X under application and click that for now because we want an application that we can actually run. And the easiest way to start is with having something that can run on our Max now in future classes, there will definitely be IOS applications that will actually be starting with. But for now, we're going to do a command line tool that we can run right here on our Mac while we're developing. So go ahead and click. Next. Um, you want to give it a name, you can name it. Anything you could name it. I'll just name it number. Game. Um, you can have your organization name. You can have your organization identifier, preferably something like calm and then a period. And then whatever your organization name is without any caps or special characters or spaces. So it really doesn't matter where the format is until you get later on, um, down here where it says language, this may be objective C or it may be something different, but we're actually gonna be coating and swift since you guys have been learning that already, and it is the newest of the languages. So we're gonna go ahead and click next, and it just save it wherever you want to just gonna save it onto the desktop, because it is the easiest to get to. So now that you have your file up, this is going to be a bit of a new experience. You'll see that your game is ready up here at the top. Um, you'll have this file over here on the side called main dot swift, and it already has some text in it. Your it's importing a foundation. Um, and so that's just the the file. If you remember back from the playground, Apple imports their own stuff toe work in the background so that we don't have Teoh at all these frameworks and that are really long and hard to explain. So leave them alone. Always keep that in there, but we're gonna clean up this code a little bit. We're gonna take out all of the green highlighted stuff you can add in notes later if you'd like, and all you should be left with is this import foundation and this print Hello, world. If we decipher this little line of code right here Ah, the print function is just telling X could that we want to out put something onto the Moche onto the machine. So what this is going to print is hello, comma world exclamation point on Teoh the results of our program so if you want to, just go ahead and click the little play button up here in the upper left hand corner. Um, and you'll see that it is running the program. Now, after you run that, you'll see a box that pops up here down at the bottom of the screen. And this is where the code actually runs that we have input appear at the top. So if you look down here at the bottom, you can see exactly hello, comma world exclamation point and then a program in notification, just letting us know that it got to the end of the program. Now, if you take note, the difference between this and what we're working board in before with playground is that if we change this to hello there, um and then we just leave it. Nothing is goingto happen. Our program has already run down here a the bottom, but it stopped, and it doesn't continuously update. So we have to go up here to the play button again, take re compile it, and then after a while, you'll see it appeared down here at the bottom with the new text that we entered. So that's one of the major differences between these two things. But we can actually get input down here in the text box when we need it later for our little number Guessing game. That's it for this set up video. Guys, go ahead and delete the print. Hello there function. We're just going to start with Import Foundation whenever we start dealing with our files, but you'll see that in the next video. So I hope you enjoy this one and stay tuned. 11. Part 2: Assistant File: I, everyone and welcome back to the second part of our final project, creation of the number guessing game. This is just gonna be a really short video on an assistant file that we actually need for this project, so you'll be able to find it. I'll have a link for it somehow in the skill share where you can kind of go through and add this to your project. But first of all, you need to find that file. Um, I have it right here on my desktop. It is called assist dot swift. I'm gonna go ahead and open it up right now, just in its own window. But you don't need to open it up. This is just going Teoh, explain a little bit about what we're doing. Um, with the file, so you'll see two different methods. Here are functions. Um, will highlight the 1st 1 So you know what I'm talking about? This is just handling when someone types something in on the keyboard so that our game can actually recognize the numbers and the the string that they input. And then if something is wrong, then tell them that there's an invalid input like if they have a symbol in there or some kind of weird, uh, accidental keystroke. So this is kind of like an just in error security. Um, you guys aren't really advanced enough, Teoh. Realize or well, I'm sure you can realize, but you guys aren't advanced enough to, you know, understand what all of this is. And so we're just gonna skip over that part. I just through that in this file for you, so that you won't have to worry about that. However, the 2nd 1 is actually fairly interesting. You'll see it. It is a function called random int. And so this kind of goes in with our game that, um it is basically a function that says when given a high end right here and when given a low interview right here, um, the program will just pull a random one during that. Within that range. Eso This is basic processing behind the scenes stuff that you'll need to add in. The main message of this video is just that this needs to go into your ex code project. So once you download it from the skill share site, you'll be able to find it on the course page. Probably either link to this video or just linked to the whole class itself. Um, so we'll click the X on that. Just put it somewhere like your desktop or something for now. But we're going Teoh, open up our, um, number game that we created last time. Remember? All the you should have is this import foundation. Um always remembered Teoh, save your file whenever you're working on it so that you don't lose anything. But all we're going to dio is just take this assist, not swift and drag it straight over here under the number game, you could put it above or below your main dot swift. It really doesn't matter, and then just drop it. And what will pull up is this? Ah, little dialog box telling you that we're going to copy it here? Do you want to copy the item to the actual folder? And we do We want Teoh copy. Make sure this box of selected here we want to copy the item to the folder to our number game folder so that if we ever delete this file on a desktop, which I assume we will, it will still be in our number. Game, project file. So hit finish. And there you go. It should be added if you open up this number game file here, and this is in your project, so you don't have to do this. But this is just to confirm that right here in our project file, we do indeed have the assist us with copied to it so we can go here on a desktop and delete the one that was downloaded directly from the skill share site. And so that's all you should be left with for this one. I just wantedto quickly add that in there so that you weren't surprised that we were adding in a new assistant file to help us out. The code that we've learned so far is fairly basic, but you can do a lot with it. So we just needed this assistant file in the back end. Teoh, help us out a little bit. And then everything from here on out you should be able to understand. And I walk you through exactly what we're typing out. So when you come back in the next video, we're actually going to be starting our project and typing it right here on this screen. Thanks for watching guys 12. Part 3: Foundation Code: Hi, guys. And welcome Teoh Part three of our number game project coding. So today I'm really excited because we're actually going to be coating some. Andi, um, going to be getting started on our project. Now, keep in mind that everything we dio you should still go through, um, and still code and still produced the same results that everyone else does. However, at the very end, I encourage you to go back through all of this change things alter things, make them cooler, make them more complicated. Because after this tutorial, you will understand, Um, the code that we go through a lot better. All right, So without further ado, let's go ahead and get started. The only thing that you should have on your file right now is the Import Foundation. Remember? That's just apple bringing in the background stuff. So what we're going to do is start by creating a variable for our game. Um, actually, it's going to be a constant because we don't want this to change during the program. We're not going to be altering it. We won't be multiplying it. It's just a value that we need. So we're going to go ahead and just type in. Let choose a name for your variable. Could be anything you want. Just remember that whatever you name, these variables, they have to stay consistent. If you name your first variable answer like I do and then later on, you referenced it as Billy because you wanted to change it. Remember, you have to change that throughout your code. Otherwise you're gonna have errors. So we're going to say, Let answer the name of the variable equal, um, random. And on dso what you'll see appear here. Eyes actually from our system file. Remember, we were going of that in the last lesson and talking about this function named random and that actually lets us select a high and low value between the two. So let's go ahead and follow exactly what it says. Um, we could come in our low and a comma and just typing high, and we want our hive variable. So my numbers are going, Teoh fall between zero and 100. Low value being zero in the high value being 100. This is the random number that the game is just gonna produce for us. So we won't know what it is until we guess it correctly. It's going to be completely random every time you run the program, but you can make this one in 1000. You could make this. You know you can make this 100 through 1000. It's just a low and a high number that you want your injures two or the random imager to fall with them. So if we have 0 to 100 it's a little bit of a gap where it makes it challenging to guess the number but not impossible. So we're gonna go ahead and use that. Then just go ahead and hit enter twice on, and we're actually going to use a print function here. Now, As we discussed earlier, anything that we put in this print function is actually going to print out to the user whoever's playing your game down at the bottom of the screen when we had our hello there text. Remember, this doesn't clear out until we go into our own experiment was less we hit this little trash can down here, so we're going to put in print, and we're just gonna tell the user to enter a number between one and 100. So what this is going to do is it's going to pop up on the screen and tell the user to actually enter a number between one and 100. Obviously, if you had your you had your range going from, you know, 100 to 1000 then you would want to change that Teoh 100 to 1000. So this is just some text letting the user know you condone. You can let it say whatever you want. You can say hello there in turn number between the one and 100. So what we're gonna do is press enter twice after that. And we're actually going to create a variable this time. Not a constant so far, and we're going to name it. Guess since this is the variable that's going to be assigned Teoh, whatever the user types in as their guest, their guest for that time Ah, and we'll just assign a value of seven for now. We'll change this up later on, but we'll just go ahead and sign of the value for now. No, the next part of this curd is actually going to be on if else statement. So if you haven't watched that video yet, you should definitely give you that because it's in the same exact format. We're just going to be using some printed outputs and some mathematical functions instead of dealing with strings within our code. So we're going to go ahead and pledge if and then, um, remember where you created the guests variable up about. So you're going to go him Type guests. And if that is greater, then, um, this variable that we have up here, which is answer, uh, which is a random inter between 0 100 We're going Teoh safe. That's greater than answer. And then have our little curly bracket we want to print out to the user. Um, answer is lower, right? And so if the number that the user inputs is actually lower than whatever they talked in, it is going to print out. Answer is lower exclamation point. Now we need something for if the answer is higher, so we want to play else. If they say if I guess is less than the answer and then remember your open curly bracket, press the enter key and it will put the close one down there for you. We want the program to print out on the screen. Answer is higher. All right, so we've got our to condition statements. If the guests that you the user inputs is higher than the random number, then it will output that. And if his lower than the random number, then it will output. Um, that as well. So we have two options right now, we need our third. So if it's we have a function or we have an if statement for if it's higher and if it's lower. So now we need one. That is just a catch all, which in this case, the catch all is only going to be If the answer is spot on. Exactly. Correct. We're going to print the stream, correct the answer. Waas. And then this is a new bit of code for you guys were actually going Teoh put in a forward slash or backslash read it, um, and on open parentheses and didn't type the, um the name of our variable that we want to actually insert in this text and then quit. Um, our ending parentheses. All right, So what? We're going to take a look at here is just this little bit. If you remember a future a few tutorials ago, we actually just added strings together. So you could have, um a string Ah, variable string that said your first name and then a variable string that said your last name. And if you put a plus in between them in the print statement, you would actually print both your first and last name siding one another. So what this is doing? Is this just just another way of doing that? Um, were actually in putting answer right there from up here. And you can see it highlights each of them every time. Get. You've used them correctly, so you can kind of go through your code and see where it's been used. Um, but you'll have this function or this. Its statement. Ah, that presents the answer exactly how it was selected by the program. And it will show up in text exactly this way when the program ends. Now, we're going to run our program for the very first time just to see, um, if the program is working, and if there are any bugs that we need to sort out, so we're going to go up here to the upper left hand corner and click the play button. Now, remember, if you look at our code, the variable guests is set to seven. So we didn't have any input in that. We just put it in, um, and it was selected for us, Sort of. You could change that to 50 or six. Or it doesn't matter in this case because we're going Teoh, actually have it change and be inputted by the user rather than us. The coder in the end. So what this program did is it shows a random integer between zero and 100. And then it said that our guests was seven because we just had that put in. If you look down here at the bottom, we can see hello there. Enter a number between one and 100. Exactly what we had had our text up here. And then we see that the answer is higher, which is fairly probable, considering we only guess seven fairly low gas, but that this means that our program compiled correctly and it's running and we don't have any issues. So you shouldn't see any, you know, Red boxes or stop signs or alerts or anything like that. The program should be running without any issues at this point. That's all for this video getting excited because we're getting closer and closer to being being able to produce our own game. Um, and I'm really looking forward to continuing this. So hang in there, guys. Thanks for watching. 13. Part 4: User Input: guys and welcome back to the fourth part of our actual app build in this introductory swift slash exco tutorial Today we're going to be adjusting are apt to allow for user input if you look right here, what we did last time is we just gave the variable Guess a number. But we want the user to be able to actually type in an integer and get feedback on their answer rather than us choosing it before the program even runs because that's not fun. So what we're going to dio is we're just going Teoh, come up here, put our cursor after the perent line and hit the enter twice. We need to create a constant. So what we're going to dio is typing. Let, um we're going to name that constant user input and we're going to study equal to input with the, uh, open and closed parentheses right after now you might be asking what input with the open and closed parentheses means or what it's referring to. And if you come over here on the side and go to assist that swift that file that we pulled in here, you'll see the function input with the open and closed parentheses. Right here is a string and exactly what it's all doing. So it's pulling in a string that the user types in, and it's basically changing it, um, into a variable or making sure there's no weird characters and all of that. So Ah, that's just what that function is doing. Didn't want you to get confused because we were putting in this, you know, input with an open and closed parentheses. E out of nowhere. So it's definitely in our program. Now we're just going to hit the enter twice again, and we're actually going Teoh create another constant called input as integer. Um, and what this is going to do is it's going to take that input string that they gave us and just change into something that the program can read as a number rather than a string of characters that haven't been assigned to a specific number. So what we're going to do is type let input as ent be our, um, constants name it equals and user input from right here above. It's gonna pull that in. Um oh, backspace. We're actually going to put, um int changing it to an intruder and then put user input right there. So that's how your coach should. We should look right now. You should have two more constants added to it. We're getting the user's input from their keyboard, and then we're changing it to an integer just to make it easier for the program. Teoh understand exactly what it is. It's numbers and not just a random string of characters. The next thing that we need to do in this part is actually create an if else statement. So go ahead and tight if, um and we're actually going to create a constant and get rid of this variable that we have down below of the guests. So go ahead and put in, um, if latte gas because we're constituting that it the name of the constant is guess which we already have down here below. So we'll delete that in just a moment if let guess the name of the constant, um is equal to input as ent, like we just had up here this this new, um, you know, number that we have created for the program to read. Then we're going to open our curly brackets and hit enter so that it closes them for us. Go ahead now and just delete this of our guests equal seven because we're actually letting them guess. Now we're not, you know, pulling in our own stuff before the program is created. And we're actually going to take all of this right here, highlight it and then hit command X on your keyboard to cut it, put your cursor inside of the if statement, and then command the Teoh paste it right inside of our if statement. And there you have it. We have our if statement. However, we need an error, Teoh, or we need a ah statement. Teoh, catch any errors if this doesn't hold? Sure. Like if I guess if there is no interviewer there, if someone put in, you know, some kind of weird character. So where we're going to do is create a catch all down here at the bottom with an else statement. So this is going to catch anything else that might come through the program, get your space bar, and then the open, open curly bracket and hit Enter and it should give you your ending one down there and what we're going to do is just create a print statement telling the user that, uh, the input waas invalid. Try again entering only a number, and then we're going to close that off. You can put whatever you want there. So that's it for this tutorial. Guys, if you want, just take a second and come up here to the upper left corner. Hit the run button. Um, and we're actually going to try this out, giving user input. Teoh, tell the program what we want to dio. So, as you can see, after we get that run, but in down here in the bottom, you can see hello there. Enter a number between one and 100 so well into our number, um, will say 82 and then hit the enter key. And it says that the answer that was randomly generated is lower than that. And then it ended with exit code. So the problem here is that you only get one chance you don't get multiple chances, what we're going to do and the last major installment of this is actually make it so that this programme repeats and so that we can continue trying numbers over and ever. Thanks for watching today, guys. Have a great day 14. Part 5: Game Looping: hi, guys. And welcome back to part five, actually. And the final part to putting together our game And, um, finally being able Teoh produce something, um, that we can say that we've coated. So without further ado, let's get started. So your project should look like this right now, And, um, if you remember from last time, we can enter in this number, we chose 80 to the program, told us it was lower, and then it ended. So that's the one thing that we're going to fix today. We're going to add in a looping mechanism that makes this program loop over and over again until the person guesses the right answer. And actually, you know, completes the game. So what we're going to dio is we're actually going to introduce a little bit of a new concept today. It's going to be a while, Luke, or just a loop in general to be able to loop our program over and ever. So we're going to hit the enter key twice, and we're just going to type up a while and then true at the space bar and an open parentheses, E. Now what? This is going to do is it's going to run everything that's inside of this bracket over and over. While it's true, Um, so what we're going to do is hit the enter key. It's going to create the bracket underneath for us, and obviously we're going to need Teoh. Highlight all of this command X click inside of the while. Loop Command V. So what this is going to do is it's going to run the program over and over until something kicks it out. Or there's an air, um, and or until they correct you or the they select the right answer. So what we need to do to stop the program after they select the right answer is actually come down here in the else statement where we have correct the answer Waas and then displaying their answer. Click right after that hit, enter and then we're going to hit break. And what that does is it tells the loop to stop or, you know, get out, get outside of its own loop. So that should stop the loop after the user has selected the right answer so that it won't keep going after that, even though they will have already selected the right answer. It wouldn't make sense for the program to keep going. The other thing we need to dio is we need to tell the program to continue if there was an error, but go back up to the top. So we're going to hit, continue and hit. Enter right down here after the print of the input was invalid. Try again entering on Lee. A number in our if are in our if else statement that kind of goes outside. So make sure you have that continue in there. And then the last thing that we're going to do for our program is actually create a sort of amount of turns or amount of rounds that the user could go into. So bring your cursor up here to the top right after the let answer. Constant did the enter key and we're going to create a variable because we will be changing this so it needs to be a variable, not a constant. Um and we're just gonna name it, turn and set it equal to one, because when they're pro when our program starts up, we wanted to know that this is turned one. The user is, you know, starting out with a fresh, clean slate, and then they will be, um, guessing and the turn will be going up and up and up. So that's what we need to add in next. We need to check take this variable, which we called turn from one up to 2 to 3 to 4 to 5. Every time that the user selects an answer, So what, we're going to dio it's come down here to the very bottom right after the else statement, Um, hit the enter a couple of times and then we're going to type in turn equals turn plus one. And what this is going to do is every time this loop this while loop up here runs every time it goes through, um, it is going to add one to whatever turn is. So turn should start out at one like we have up here and then the next time around, it'll be, too, and this will add to it. So to be three 45 and it will just keep adding to itself every time it takes you, you know, to guess an answer, the very last thing we want to do is give the user a little bit of feedback on what their answer, waas and how many times it took. So we're going to put Prince, um down here at the very, very bottom of our program and let the desert the user. No, it's Chuck. You, um remember this little bit of code that we used above up here in this correct answer? Um, re pulled a power answer. So what we need to do here is pull up our turn, variable. We're gonna dio open parentheses, turn close parentheses, tries to get the right answer. All right. And so this should be everything that you need for your program to run. What it's going to dio is it's going Teoh, run a loop. Ah, which says hello there. Inter number between one and 100. It's going to get the user's input from their keyboard. It's going to change those random characters into a natural integer that the program can recognize not just a one and a two. It will actually be a 12. Um, if that guess, um is lower or greater than the answer, then it will say the answer is lower. If that guess is lower than the answer, it will say The answer is higher. Everything else it will say Correct the answer Waas and then put in the answer. Then what it will do is break. So it'll come outside this loop and it will say it took you blink, you know, turns tries to get the right answer. So, um, what it will do? Actually, let me change this to turns. Um, and this gun, it can say whatever you want. It's part of your unique code. So that's it for the tutorial. I'm going to make another video, just showing you what the program does. But that's not going to include any coding were simply just going to run it. I'm looking forward to seeing you guys, um, work on this. Create your own projects, your own variations. There's a ton you can do with what we learned in this course and just stay tuned because I'll be creating more videos that are more in depth. And you actually get to run app on your iPhone. Um, fairly soon. So stay tuned and go watch the next video to see how this program works. Thanks for watching guys 15. Part 6: Final Project Demo: hi, everyone, and welcome to the very last video of our development for this project. I am going to be showing you today how the program works on the errors are handled, but there's not actually going to be in a coating because our coating is completely done. So without further ado, let's get started. We'll click the play button up here in the upper left hand corner and, if you will direct your attention down here to the bottom right hand side of the screen, were greeted with the usual Hello there. Enter a number between one and 100. Um, let's try 12 to begin with it. Enter and it says the answer is higher. So we need Teoh. Enter a number between one and 100. Obviously. Um, so let's try the number 45. The answer is lower, so we know it's between 12 and 45. We'll try it. 35 Still lower, 25 higher. So it's between 25 35. About 30. It's higher than 30 about 32. The answer is also higher than 32 33. There we go, and if you'll look, you can see that the code actually comes out right here and it says Correct. The answer was 33. It took you seven turns to get to the right answer on, and that's pulling from this print statement just down here. So as you can see, our code is running through, it seems to be running smoothly. It picks a random number. It'll be the It'll be different between zero and 100 every time. Because of this statement up here, Um, and you can change that, however you'd like. So let's go ahead and clear this out and try entering a letter to see how that Harris handled. So we're agreed to with the usual hello there. Enter a number between one and 100. We'll try a we hit enter and it says the input was invalid. Try again, entering on Lee a number and you'll see this down below. In our else statement, try again entering only a number so it wants us toe Onley. Enter numbers that it can change into integers so that the program can actually work. Just to show you it's random. We'll go through this again. We'll try. 25. It's higher. 50 lower, 30 higher than 30. 24 higher than 34 about 40 still higher and lower than 45 UM, 43 42. There it is. The correct answer. That time was 42. It took you eight turns to get to the right answer. And then the program ended. So you can dio a 1,000,000 different things with the code that we've laid out here. You can change what statements air there. You can change when the statements appear. You can create it entirely different game that has to do with guessing numbers. Maybe, um, you have a range on the top in a range on the bottom. And you know, you there's just a 1,000,000 different things and I don't want to give you too many ideas because I'd love to see your projects that have to do with using the code we took here, um, manipulating it in any way you can and go watch the other tutorials about how you can add strings of text together, how you can add and multiply and divide and subtract numbers from and to each other. You know, you can create a wealth of math games with the information that has been presented in this set of tutorials. So I hope you guys really enjoyed it. Thank you for tuning into this class. Um, and be on the lookout. Go ahead and follow me on skill share. Be on the lookout for future classes because I will be doing and publishing more classes that are more advanced. And pretty soon you'll be running your own apse on your iPhone. Um, you'll be able to show them to friends and family and even put him on the APP store eventually. So thank you guys for watching. I appreciate the support.