 Well, hello everyone and welcome to Sailor Academy's PRDV 401 introduction to JavaScript This is our unit for review if you haven't seen any Videos in this series yet check down in the description below their link there as well as a Link to the entire course because this these videos are a supplement to the entire course So make sure you guys are falling along with the course with us And if you have any questions as we're going along you can leave them in the chat box on the side I'll to be keeping an eye on that Or you can leave them in the comment section below for if you're watching one of these later But you know everyone's busy, so we'll just hop right into it And I'll hand it over to Susan White and she can get us going and I'll be here if you guys need me All right, thanks Mike. All right, so we're in unit four now. So let's get started Okay, who am I? I am Susan Hoyt. I'm from Houston, Texas. I have been a computer science educator for about 25 years I've been with Sailor for a little over a year now I do love to teach coding. It opens up a whole new world for so many people and there's so many Instances that you might need it or use it or find a job that uses it In my spare time, I do hang out with my dogs I apologize if somehow you hear them in the background barking and I do like to read a good book and I'm all about the sand and the beach and the warm weather All right So this is going to be our first in the series of three courses that will eventually be out that cover the JavaScript language There's six units in this course. We are on unit four today So we have done one two and three and those are already on YouTube and you can go look at them if you miss those you can always go back and look at those and Get caught up on that sense Whoa, sorry, I do that all the time with this mouse All right, so we're gonna start unit four last week. We did cover unit three In that as we talk about the certification I always want to say it every time that we go through this And the course final exam not the each unit test But on the course final exam you do have to score 70 in order to receive your certificate You can retake that exam as many times as you need to get that actual 70 But you do have to wait a week apart to take the other test But you can continue to do it All of these unit tests and all of these assessments at the end of the units will help Prepare you for that so that way you may not have to take it more than one time Okay We'll also talk about Code Runner and we'll talk about Code Runner again today Just so that you can kind of see how that works for coding in our assessments and then We actually use some developer tools last week to run some of our coding code examples And these are the topics that we covered. We did a lot of topics last week. So it's a pretty long Video so we had variables operators keywords. We did values and data types We talked about operators. We actually wrote some simple JavaScript statements and then we looked at a few different editors We we will look at jet JS hands again today We will look at replete again today and we will look at Code Runner again today So you will see all of those again today Whoops All right, so completing this unit should take you approximately two hours What are we gonna cover in this unit? We're gonna cover conditional statements. So we're gonna talk about if else while switch I actually didn't put the rest of them on here, but we're actually gonna talk about do while and we're gonna talk about for loops and Test all those out and do some examples and see what kind of little small mistakes that you want to be careful of We will use relational Boolean operators with conditional statements and we'll write some code that implements interactive choices based on a condition So if you enter something You'll have a choice based on that. So we'll do some of those examples together All right, so let's get started on conditional statements. So what is actually control flow? Control flow in your program can be sequential. It can be selection and it can be repetition For sequential, we're talking about just a straight line I started at the top of that program and I just go line by line all the way to the end and very rarely Do I have programs that are interactive that would be something like that? So we definitely have to get past that sequential execution and get into some conditional stuff here So in our conditional you see that we're no longer going just a straight line from left to right We're coming from the left. Okay. Now we're gonna hit something here and this is gonna be a decision in This decision if we select say true, we'll go this way and if we select false we go that way So this is an example of like an if statement. So the if statement Would have this if it's true do this otherwise do that and so As we go through we have some if-else's that we'll see and those if-else's will have some more branching off stuff So we're gonna look at some examples and go ahead and start out with our examples here So in my examples Let me grab over here And I will put them here I'm gonna go straight to the course and show you where this is So if you notice here, I grabbed the link, but I'm in unit 4 if you haven't done 3 2 or 1 You definitely want to go back and do those so I'm in unit 4 and I went here and I'm looking at the control flow And you see over here it gives me a table of contents and shows me where I'm at so right now we're in control flow and conditional execution So what we want to look at here is we've got some if's and here's the little graphic I just showed you so we're gonna grab this if statement And I'm gonna bring it into replete remember. I showed you replete before if not, it's replete com and Then you make your own login and then when I go create the one that I like to choose is the node.js Again, if you've seen this it makes weird names. I don't really care those weird names can stay there And I wait for it to get ready and then I'm just gonna throw my code over here And I'm gonna try it out So if you see here, I'm gonna go ahead and just run it real fast And I'm gonna let you see what it looks like and then we're gonna talk about the parts So if I run it, it tells me to pick a number. Okay. I have no idea what a number is gonna do So I'm gonna do 25 Okay, so it tells me that 25 is the square root of 625 And it only runs at one time because we haven't done repetition yet So if you notice here, we did our let the number equal So this is our prompt which you'll have to use a prompt later in the actual Exam for this unit. So Remembering how to do a prompt would be helpful So you can always go back and look at these examples to help you now here We're using a Boolean knot which we covered last week So we said if our number is NAN we covered NAN last week. So what does that mean if my number is not a number? Not then I will do something and so let's happen if I run it and I say it is not a number I'm gonna say the word five Did it do anything Nope, it did not because it only will do this if If it is not Not a number. I know that sounds like a double negative, but this is gonna return true If whatever I enter here is Not a number it will be true So if it is not a number I don't want it to do this So I want it to be false and not do the if Because how does the if work? Well, we got the word if what you can tell is a keyword just like let is Then we have the parentheses these outer parentheses will contain where our Boolean statement is whatever statement we put into the if here has to has to Be either true or false whenever it evaluates. So this is our Boolean statement and Then once it evaluates if this statement is in fact true Then it will come in here and it will do whatever is in here If this statement is false in this case, I don't have an else or anything. So that means if I have some kind of Statements down here or anything like that What state notes if I need statements down here Then it would just skip it and go to whatever statement I have down here Now if I do something that is a number so let's do 12 this time 12 is a number. So it came in here and it did console log and it said the words Your number is the square root of this plus means. Hey, I want you to concatenate this To this string and notice whenever it prints out It's all on one line like that and then I took the number which was what they entered and I multiplied it by itself Also notice here. I did make sure their prompt was a number So I need it to be a number in order to do some kind of calculation with it. Alright, so now let's move on to the other one Let's try this one Now this one is pretty basic Notice we have an if again and we have our parentheses Inside those parentheses has to be some kind of a statement that would evaluate to either true or false One plus one equal equal to that is a statement that could evaluate as either true or false So let's run it and see what it says It says it's true. Now last week. We also talked about You can use three equal signs so that it makes sure things are the same on both sides And it's still true that way. So don't forget about these three because those are also good things to use Now, how does it if look a different because we put it all on one line Putting it all on one line that looks fine, but sometimes it's much better to come over here And replete automatically and did it that for me But if you indent it over here Then sometimes it's easier to see the actual flow of the program rather than having it all on one line Because a lot of stuff in JavaScript you can put all on one line and it looks terrible, but it'll still run with no problem Alright, so let's do another one now and we're going to add in else So How does the else look as opposed to just in it Alright, we still have our prompt which is a number. We still have the same if that we talked about But notice here that now I have an else The else is evaluated only if the if is false. So if this statement right here is a false statement Then it will execute the else So when I execute the else it says hey, why didn't you give me a number because this will only evaluate if It is not a number Now some people will when they first start doing this They will want to put something here and they'll want to put like else number Is and they'll want to put the opposite here You don't want to do that because you don't have to and it will not work So this else should not have any kind of condition next to it. This else works Because if this is false, I do the else if this is true. I do the if And that's the only thing that's That's different on this. So let's do this and let's do it with Five like that And so five is not a number. So this became false So it went down here and said hey, why didn't you give me a number Now if I run it and I actually do the number five It actually tells me I went inside the if now and I did this statement So that's an if else now. Do we have other stuff that we can use Notice this one this one has even more else's Now you know how I tried to put this here and I said don't do that because you really don't want to put a condition there If you think you might need another condition then you may need something like this Where you're going if something else if something else else if this other thing So this is a nested if else So notice for every if or for every else you've got to match it with it with an if you can just have it randomly there So if I have this else I can follow this curly brace back to see what if it connects to If I don't have curly braces for any reason and else is attached to the closest if So let's see what would happen here. We are having them pick the number If it's less than 10 we should say small if it's less than a hundred We should say small if it's less than a hundred. We should say medium and if it's anything else we're going to say large. So let's try this All right, so I'm going to do a number less than 10. So I'm going to do five Small okay that works If number is less than a hundred. Okay, so I'm going to pick Nine That's still small because it gets hit right here by this one Now what do you think's going to happen if I hit 10 10 is greater than 10 so this one is going to be false So now it's going to come here and is number less than a hundred Yep So now it's going to say medium now. How do I get this one to happen? Well it has to be a number that looks like it's going to be let's try one greater than a hundred or let's just try one greater than a hundred Let's just try a hundred because this one says less than so let's do a 100 And a hundred got us to large Now if we had tried to do this with just ifs we would have run into a problem because Let's do this real fast. I'm going to take off these Let's make sure I take them off right. I may have extra curly braces You do Help me do I'll put it else here with this Okay, so this one matches with that and this matches with that So Basically I have an if Number is less than 10 do small if numbers less than a hundred do medium else do large So let's see what happens here and why it looks different. So I'm going to pick not So since I did not have that else It hit this if and it hit this one Because nine is less than 10 and I didn't have the else that made it avoid this one if I put that else Then it says, okay, I only do any of these else is if this one wasn't true So when you're trying to do stuff a lot of times when you're trying to break it into ranges or like great like say doing grades Anything like that. You definitely need some if else is in there All right, let's see if I I Did want to show if you don't put any curly braces after it. Yeah, so let me do this All right, so I could say if number is equal to 10 less than 10 We're going to change this one around a bit and I'm going to say console log Less than 10 Okay, then I'm going to have something else That I want to happen that in the same thing console log And the same thing console log Okay So let's say I wanted these two statements to happen if the number was less than 10 so I run it I'm going to pick a number less than 10 Okay Even though I indented like this some of you may be coming from Python and you're used to indenting like this and you're like, okay Well, if I indent it knows I mean it to go with that if absolutely not In JavaScript, you've got to add the curly braces to let it know. Hey, I want you to do more than one statement So now if I do nine It shows both. Okay. That's if I wanted both. Okay. Now. What if I only wanted one I can change it and I can put a curly brace there or if I just wanted this to happen all the time. I can leave it like that So if I wanted This looks great. This looks like this is going to happen all the time. So whoops Hold on Oh, I've got a curly brace. Hold on. Let's get rid of that one Try that again All right, picking a number nine nine should be less than 10 and this happens all the time So Again If I did this It looks like it's always going to happen. So if I did 10 Let's do 10 This happens all the time even though I indented it because I did not put it in a curly brace or Basically if you want more than one statement in your if you have to have a probe race Let me stop talking in circles. All right. Let's move on. Let me see. I think I got all those All right. Let's head on All right. So we did the first part where we talked about using an if or an if else and now we really need to talk about loops So let's look at some while and do while loops. So let's start here. All right So I'm going to grab this I'm going to throw it over here into replet real fast. All right. So if I run this This will show me all the even numbers between zero and 12. Okay, so this is great But what if I wanted all the even numbers between zero and five thousand? I would not want to write five thousand lines of code. So that's where loops come in and that's where they're great to have So let's look at a loop And talk about the different parts of it really fast So I want a loop that does the same thing So a loop has three parts. It has a starting condition It has Some kind of conditional to make it stop and it has to have a way to change that starting condition so that it gets closer To this condition so that the loop is not an infinite loop So part one. So this is our part one Our condition right here is going to be our part two And our changing of that condition to get it closer is going to be our part three All right, so let's see what happens when I run this Exactly the same output instead of having all those lines of stuff I only have these and the best thing about it is that I could totally make this go to five thousand if I wanted let's just do five hundred And easily goes to five hundred took a couple seconds not a big deal now a couple of things to think about and let's go back to 12 all right, so we went from zero to 12 whenever we did it A lot of times you'll see me start counting at zero because a lot of the computers will count from zero Now there's a couple of different things that you can see in a loop. We have the wild condition And just like the if we have these parentheses and these Will contain a condition that if it's true it does a loop if it's false it would come down here and do whatever Statements are down here So Whenever you're doing the loop things to think about is how you want it to display if I wanted it to display zero to twelve Like my other one did great. That's what it did But sometimes you might accidentally do something like this and you switch the order of your stuff And I'm just going to comment out this previous one. So now notice. What am I doing first? I am adding two to it before I actually view it or print it so in this case Instead of it going from zero to twelve it goes from two to fourteen. So let's see why When you go through a loop the first thing it does is it takes your initial value. So the number is zero So we come here and is zero less than or equal to twelve. Yes, it is. So immediately I come into the loop I immediately in this case add two to my number so number immediately goes from zero to two and then I print it So that's where this two came from right here Then what I do and I'm just going to remove this one for right now so that you don't get confused Then I don't just go on to the next statements. I come back up When I come back up my number was two Okay, that's what I just printed. So now I come back up to my condition and I say is two less than or equal to twelve If two is less than or equal to twelve then I do the loop again So it is so I would do two plus two so now number would be four and I would print four Then I would come back up is four less than equal to twelve. Yes So then I would add two to four which is now six and I print six and then eight and then ten And then twelve Now when number was twelve it was still less than or equal to twelve So number becomes fourteen I will print fourteen even though it says number less than or equal to twelve A lot of people when they first look at loops they get confused and they go okay Well my number was twelve and so I came in here and my number became fourteen So then I should leave the loop No, you don't leave the loop in the middle like that unless I throw in a break and I'll show you how to do that later But it only leaves the loop when it comes up here and it checks then it's going to leave the loop So it was fourteen it printed fourteen Now it's going to check it and fourteen will not be less than or equal to twelve so it will leave the loop now and so It all depends on how you want things to show up So if I wanted this to be like it was to start with We would switch that and then this case Oops Sorry I didn't mean to do that Hold on Try that again Let's see Alright so let's get rid of this one. It's time to go back to how we used to be Alright so this is how we were to start with So in this case fourteen doesn't get shown because I print the number before I increase it So those are just some statements there for you to remember and let me grab the other hold on Clicking too many windows here. Sorry Let's grab this one now and let's see what this does This is another while Alright so this while has a result And a counter Now notice I have this counter here and I have the counter here So sometimes you'll hear it called the loop control variable or they'll call it LCB for loop control variable Because the counter is the one that's controlling the loop. If this is true, our loop happens Notice I'm changing my counter in here and I'm making sure I change it so it gets closer to ten Because it started at zero so adding a little bit more of a counter It's going to get closer to ten because it started at zero so adding one to it means it's going to get closer to ten So let's run this really fast Now what did this do This did two to the tenth power So now watch if I did a couple of tricky things here What if I accidentally did Let's do Counter is equal to counter minus one Let's do that for a minute And I don't even see something happening because my counter is doing weird stuff so I I'm like I don't know what happened let's try Checking the couple of things you always want to check whenever you have a loop that's giving you some problems Is always check this condition Make sure because if I if I'm thinking in my head I need this counter to go until it's greater than ten Sometimes I'll accidentally write that And so if you notice here what did my counter start with this is my step one My counter started at zero So is it ever even going to get into this loop No it isn't because zero isn't greater than ten So in your mind when you're thinking okay I need to finish this loop when it's greater than ten Always kind of think about okay well I wanted to finish them but when do I want it to go through the loop But you make sure you get the less than or the greater than in the right way Because watch if I would have done greater than here It said one because result was one And then I did not go through this loop because counter was zero it's not greater than ten So when I printed the result I printed my original one So again this is our step two this is our thing that controls our loop And then this is us changing our condition so it gets closer so that we can get out of it Always check this now if we were trying to do greater than ten We would have to have our counter start at something bigger Okay so we'd have to have it start at something bigger And then we'd have to be careful on this because counter's twenty so that would go in and result would be this And then if I kept adding to counter would this loop ever stop If I have output and it's looking like this and nothing seems to be happening it could be an infinite loop So always go back and check am I is this right are these right and go and check all those step one two and threes to make sure you're doing the right thing Whoops alright let's do another one This one looks a little different If you look here our while we always checks the condition first before it goes into the loop now watch this one that I'm going to show you This one says do and then it has curly braces after those curly braces at the bottom it says while and then it has its condition and a semicolon When you are using it do while and that's what it is called the thing about this loop is that you are guaranteed for it to happen one time So if you know that you are having someone enter things or something like that where you know hey I need them to do this loop at least one time no matter what Then you want to do while so watch what happens here Okay so it asked me who I am so I say my name Then it's going to say while it's not your name so while I haven't entered anything it's going to keep asking me I entered something right So if I hit enter it just prints my name but let's see what happens when I don't enter anything It continues to ask me hey who are you can you enter something so I can put this loop Sometimes you could see a do while going for a password type program Because you need them to definitely enter the password at least one time to check and see if it's correct So you'd say do enter the password while the password isn't correct I keep asking them to enter it I can have other things like that Alright so let's move back over here for a second and let me see if I did everything I got to do the for loop example which I think is the next one let me do next page I think I have to do next page and next page yes Now I want to do a for loop so I'm going to show you a for loop Some people prefer for loops over wild loops some people are the opposite They all can kind of be configured so that they can all do the same thing so watch this one Whoops Oh I missed the semicolon Alright then this program looks familiar it goes from 0 to 12 so it's doing all the even numbers Here's where the for loop is kind of nice the for loop has step one Then step two and step three all on one spot That way you make sure that you have all three of those if you want so in this case we're starting with number zero We will continue this loop while number is less than or equal to 12 and each time we will add number or increase number by two Okay some people accidentally do this a lot and they would put number plus two and that does not change that original number So we have to have something like number equals number plus two or we can use a shortcut notation that we talked about last time which is plus equal Two and that means the same thing so if I run it same output Okay and same thing now this would be a little harder to change from that while loop or to print out the 14 I would have to start it at two And then I'd have to have it go to 14 here can I still have it work Of course I just have to change up things a little bit differently on how I'm how I'm printing stuff out Alright so that's the first for loop which has again step one semicolon step two semicolon step three semicolon Now then I'm going to write something out here let's do Okay so I'm going to put that there real fast And some people when they do for loops they accidentally do that Let's see if I can make it work like I want Whoops that's going to tell me number is not defined because I have stopped my while loop and I defined my number in there Now I could also have something like this happen Let's number equal two And then I could just do number equals two here Now notice I did not get the same thing it only printed out 16 Okay so what happens whenever you have it and you accidentally put a semicolon at the end of your for loop Is that your for loop now becomes this one statement and it has no code associated with it So it will do the whole loop and it will finish and once it finishes number was 16 And so now this is just like another statement And it prints out 16 So that is a huge thing to be careful of because I can't tell you how many times people forget and put a semicolon there Or they put a semicolon at the end of their if If you had an if and I'll show you that again whenever I go through some if you accidentally put a semicolon at the end of that You will have problems in a while loop if you put a semicolon there you will have a problem in a do while you do need one On the bottom so I will show you that again don't worry. Okay, let's look at this one now. All right, so now we are going to go and we are going to do the power to Oh, I forgot the console long hello. I can spoil that be helpful. All right, so let's see what our result was. 1024 same thing we got on our while. So we have our results and notice we had to start our results at one. That's a mathematical thing because if we started at zero we would end up with zero because zero times anything is going to end up being zero. Things to look at here again be careful don't put your semicolon here. Our counter equals counter plus one. Don't just leave it like this because that'll cause you problems, and you can actually write it like this and make it a little bit shorter and say counter plus equal one, or even better since we're only increasing by one, we can go counter plus plus. So that's another good way to write, and it makes it easy to read. Now, if I run it. I get 1024. Okay, what do you think is going to happen if I go and I take this print. And I also put it in here. I'm going to comment out this one right now and not have it, and I'm just going to run it. Now, since I put the print statement inside the four. Now I have what every single time I go through the loop it prints. Sometimes if you're having problems and not knowing if your loop is happening it's always helpful to put a print inside there and make sure that you can check and see what your loop is doing. All right, I think that's the last of my four. Okay. Let's move on here. Okay, quick notes about it. Make it look nicer again. Okay, most loops will exit when that loop control variable Boolean statement is false. We can also use break and break will jump out of the loop. Another keyword using looping is continue the keyword continue will make it skip that iteration and go on to the next one. Okay, so I just looked at this, instead of using counter, we can use counter plus one counter plus equal one or like I just did a minute ago. I did counter plus plus, and those will all add one to count. Now let's look at an example of the break will pass. Let me get here. Right. So here we're going to break out of a loop. I'm going to show you it with a for loop. It's a little different. And again, all these examples that I'm getting are from the actual course. So as you go through the course and look through it you'll see all these. All right, so look at this I'm going to run it real fast. So it looks like it prints 21 and stop so let's see what's going on. Notice I have my part one of my for loop, but look what I'm missing. I'm missing part two, I'm missing a condition. So that means this loop could potentially go on forever. I have my current equals current plus one, which we just can change that if we want to. Now, this is my if, if current modulus seven, what does that mean. That means if whatever current is is evenly divisible by seven. Okay, because I said equal equals zero. Remember modulus is remainder division. So it's takes current divides it by seven gets that remainder. If that remainder zero that means it was divisible by seven, and I will print it. So 21 is definitely divisible by seven. Then instead of repeating my loop, I will break. All right. What happens if I don't break. Let's see. I don't know. Do you see that now I am in an infinite loop. Luckily for me, I can just press stop here and it doesn't kill my computer, but I can press stop and it will finish. So if I didn't break and I didn't have this condition notice it will go on forever. And we don't want that. So that's why breaks can be handy sometimes they will get you out of that loop. All right. All right, here's some more if statements that I just wanted to show you on how they look on their syntax. So with our if we have our condition inside the parentheses. We do not put a semi colon here because if you put a semi colon there you're going to have problems with our else we don't have a semi colon either. And with our else we do not need a condition next to it. The only person who's going to have a condition next to it would be an if. So we could have an if with its condition and then else with another if and have its condition. So, whenever you're having your else ifs, make sure you do some kind of indentation make it look nice, make it easy for you to come back and review. All right, now we're going to talk really quick about switch cases. Switch case is another way that you could use basically like an if else. So, there is an example in action where they go through a whole switch case and this is what it looks like. And I have it and I'm going to show you a couple things from that actual video, but I highly suggest you watch that video because they go through it step by step and show you different things. All right, now all the different parts of the switch when I get it over here, and we'll talk about it how it works. Let me grab it real fast. All right, let's get the switch going. All right, so I have this bar today is remember with bar I could also say, let and it would be fine. Okay. So, what is happening here is that I am deciding that Sunday is zero. Monday is one Tuesday is two and Wednesday is three and so on. Six is going to be Saturday. So zero Sunday, six is Saturday. So in this case, I'm starting to count at zero, which I told you is a common thing with computer science stuff. I started counting Sunday at zero Saturday is six. So there are seven days for sure. Now, I print out at the end what I'm going to make my date statement be. If you notice, I have two cases here together and I'll explain those in a minute, but you should notice that I say the word first I say switch. What variable I want to switch on. So in this case, I'm going to switch on whatever today is value is. So these cases tell me, okay, if today's case is zero. And it's six. Okay, so those are two different things that it could be, then it's going to do this. If the case is one, it's going to do this. If the case is two, it's going to do this. Now what I want to show you here is after every case statement, there's a break. If you don't put a break, you run into problems. Some people like to put the break on the next line like this. Some people prefer to put it at the end here like that and line it up that way. Whatever works for you is fine. You just can't forget to put a break and I'll show you what happens if you do in the second. All right, so if I were to run this today is zero. So it says it's the weekend, it's time to program. Notice after case zero, I don't have a statement. So at case zero, it goes here. And it goes ahead and does this one. And in that video they talk about why this happens and why you shouldn't do it some other ways like using a or and stuff like that so I highly recommend watching that video it's very helpful. In this case, let's go ahead and do case one. Okay, case one doesn't work. But hello. We got it wasn't input. Sorry about that. Let's make today is one. And that's Monday. That's great. Okay, let's try six. All right. Six works. Okay, now let's try something. I don't know why I keep hitting run every time. I go through all these I got right right right now I have a default down here. What does default mean default means hey, it didn't match any of these guys here so I don't know what they're putting in. So I always want to have a default down here to catch in case none of these match so let's do it as eight. And let's see if it hits that default. So it did. It went to there and I can have some kind of statement saying hey your input is incorrect, whatever kind of catch so this is kind of my catch. So this switch, you can think of it's like an if if today is zero. I do this else if it's six I do this else if it's one I do this and so you can line it up with an if else, or you can do these cases which kind of make it look nice. So what happens here though, I'm going to take this break off. Case one. Okay, I took off the break. Now watch. Say I did it again. Okay. Watch when I make it Monday. It said Tuesday, because I didn't break after I had it. So, when I do a switch case, if I start to have some weird outputs like that, I need to go back and make sure hey did I put a break everywhere and make sure that those are working. Okay, let me think there's anything else on switch case. I think that's it. Notice it does have curly braces around it. Again, the switch, what variable I'm going to switch on and then all of the cases for that variable here, and then a default that catches any of those cases you did. All right. And that was example in action. Okay, looping statements. How about a while loop with Sentinel. All right, let's do this one. What is a Sentinel value. A Sentinel value is a value that when you enter it and make sure loops stop. So, well, hello. Let me try that again. All right. I have this. So I've got a prompt for them to enter a number or a negative one to stop. Okay, I'm going to tell you right now that negative one to stop tells me, oh, that's my Sentinel value. And right here I have my while. And it says, while my input value is not negative one, then I go ahead and do this loop. I'm going to enter negative one. I will stop. So let's watch. Please enter a number. So I'm going to do five. Five squared is 25. So now if I want to spare some other numbers 12. 58 or 17, whatever I want to do when I'm tired of doing this, I'm bored of it. So now I'm going to enter negative one. So now when I enter negative one, which notice I'm entering it down here. Now, on loops where they have user input and the while loop is based on that user input, a big problem that people will forget is first I have to have a prompt to start the loop so I've got to get them to enter something to start it. If I do the loop, I have got to have them input something again, because if I forget to get another input from them, then it will never change input values will stay the same. Because remember, we've got our three things. This is step one. Get it a value. This right here is our step to some kind of way for it to stop. And then this in case of us just adding numbers are doing something. This is actually our step three that gives us a chance for it to become negative one so we can exit the loop. If we don't have this part three inside our loop, then it will never change and we'll be stuck in an infinite loop again. So over here I did negative one. And boom, I'm done. It stopped. So that is an example of a Sentinel value. All right. Four statements. All right. I don't think I need to do another one of these. I'm just going to tell you the things I had talked about. These are all the things to watch about. Make sure that you're using the right conditional right here. On this counter, I said counter plus plus instead of counter equals counter plus one or counter plus equal one. You can use whichever you like. Make sure you got all three. Don't put a semicolon here you put a semicolon here you're going to run into problems. Okay, so off by one errors. That's where I switched for my, where my printing statement was, and it went from two to 14 instead of zero to 12. So be careful on that too, and you might have to change your variables when you're doing that. Okay, so the do while creates a loop that will run into the condition is false, since it checks, hold on let's grab this. And since it checks, it will execute at least one time it's called a post test loop. And so, no matter what it's always going to run there I did that again. It's always going to run one time. Hold on a second. There we go. Okay. So we're going to grab this do while. And throw him over here. All right. So this is another do while this do while has a result that's going to be a string. And we start I at zero guess what this is this is our step one. All right, where's our condition. Oh my gosh it's at the end down here. So this is our step three. So our step two, our step three is going to be who's changing who's my loop control variable. That is step three. All right. Initialize it. Make sure I have a condition to get out and make sure somewhere I'm changing this loop control variable, so it will get me out of it. Now I'll run it real fast. All right, so I is zero. I becomes one result is result plus I. So now what would I want to print out. If I type, I would probably want to print out I and let's see what it is. That should make sense. It went from zero to five. But you might say, wait, it says I had to be less than five, but I am outside the loop here. Have I see that if I'm outside the loop, then that means it had to become five because it got out of the loop. Let's make I 25. Now down here I said I needs to be less than five, but this is a do while, not a while loop. So no matter that this will not meet that condition, it doesn't matter I go in order so I do this first and it says do I becomes I plus one so I will become 26 result will become result plus 26. And now I will check my condition. I did not check it until I got to the end. So I will always do this loop one time. So when I got down here to check it. I said, Oh, I can't go into that loop again because that doesn't meet the condition so now I should print 26. So a do while always happens at least one time. All right. So fix the switch statement. Let me show you this one and we're going to do it really quickly. All right, so as we're going through here's our practice review, fix the switch state. So I click on it. It opened up a window so I'm like, Oh, I guess I should read you what I'm supposed to do. Let's see how well you understand the syntax for switch. So this is using the Lenter JS hint which we did in unit two. So it says to go ahead and copy all this. And go ahead and throw it in here. And remember a Lenter is here to check things for you. It does not run your code. You would take this code and you could put it back over here into replete and you can check it and see if it does in fact work for it. And you notice it starts off and it says, Hey, you're missing the semicolon. So I look in line seven and I go, Oh, look how I am missing a semicolon and I put it. Notice it went away. Now look, this one is telling me I expected a break before your default, and I didn't do it. And so look, I can add my break. Then it tells me, Hey, you have a unnecessary semicolon. Okay. And now the warning. This is an okay warning. This is talking about what version of JavaScript I'm using, and that's okay. But right here it tells me I'm trying to use an undefined variable. So I go, Oh, I forgot to give fruit type. What are you like. And I could start it at nothing if I wanted. And now it's telling me, Hey, let is only an ES six. Okay, well, that's great, because I'm using it so it's not a problem. But if I changed it to bar notice that goes away. So if I use lead it's telling me, Hey, you know, something could happen and you could take this code, and you could copy it. You may have to add a few things to test it over here. Okay, so if we did it, let's see. Okay, so my fruit type was nothing. So it said default. Sorry, we're out of fruit type. And then it went outside of my switch and said, Is there anything else you'd like. So let's try one of these just real fast and I'm going to move on. Let's try cherries. Okay, so it tells me right here in the case of cherries, cherries are $3 a pound. So that's a great way to check. And sometimes if you're working over here in replete. You may not know what you messed up on because sometimes these error messages are not as good as one of these linters so you may decide to try it here first, and then bring it over here, whatever works for you. All right. What I'll have you covered today. Conditionals loops switch cases breaks continue sentinels. Let's talk about the assessment really fast and wrap this up. All right. So I'm going to go back to you know for like this. And here's my whole unit for this is all the stuff we've just talked about so now I'm going to go down to the assessment. I'm going to get to my assessment. I must say continue my attempt. I may have to refresh it. I don't remember if I saved anything. One through nine different answers, matching output tell me what the output is things like that. All right, then we hit to number 10. We get to number 10, we're going to make a temperature converter. Always make sure you read through all this stuff. You can find out the user. Okay, so you say, oh, I don't remember how to prompt or remember at the beginning of this, we did some prompts where I entered things. So you can go back and you can find out how to prompt. And then after you prompt, you're going to use if else that test for the choice. Then you'll calculate the temperature. They're asking you to use document dot right. If you use document dot right. It will write it down here for you and you'll actually see it down here. You can write it that way and you can display an alert which displays no data entered cancel selected for the choice of the 10. So how to complete it. You can contain HTML or CSS. So guess what, we're not going to bother with either of these two windows tells you to expand the jazz pain to enter all the necessary code and enter your code after the comments. So that means I come down here, and I don't want to work with this little tiny window. This is our code runner so we're going to bring it down some here and make it bigger. And I can make it bigger even if I need a bigger than that. I'm going to put my prompt here. I'm going to put however I need to do the prompt. Notice as soon as I do that my prompt comes up. So that's kind of a pain to have. So sometimes you might decide, okay, well, first of all, where did my let go. Your lead is here. It is just really light blue, and your bar up here is there is just really light blue. Now notice, did you see what's telling me I was missing a semicolon. Sometimes when I do these prompts, I will comment out, do the coding for the prompt, and then run it that way I don't have to deal with all that. Then I'll have another one here where I prompt for the temperature. Then in here, I will have some kind of it. It will be like if choice. So I'm going to do equal equal or it could be really careful and do equal equal with three of them. And so if they said see, then I'm going to convert from Celsius to Fahrenheit. And then else I would do the other or however you want to set it up. I'm not going to write out the whole thing because I definitely want you to practice doing this. So that's exactly how to do the prompt. Go back and look at the other code that we have talked about. Okay, so let's finish this up. Again, the letter R is hard to see but it's there promise. And you may want to comment out that alert, or any kind of prompt or anything that you're doing that will be annoying. All right, that is it from unit four next week is unified the basics of functions, completing that unit on five should take approximately two hours. We're going to talk about how to identify types of functions, how to use functions with arguments, compare the different type of function decorations and write code that actually calls the function. Our next live session is December 6 at 530 Eastern and we will cover unit five. Thank you. And I hope you learned something today about all this looping and if else. All right, well, first let me just say, well thank you for taking us through that that that was great thank you as always. And thank you everyone for joining us. And of course, if you haven't, if you weren't joining us live, you know, you had a question feel free to leave it in the comments. We'll get to it if we see it there. And of course just a reminder that this is just one of our larger series of videos that you can find in a playlist down below that are covering in our just a review of Sailor Academy's JavaScript course, which you can find the full course of linked below as well. But again, thank you everyone for joining us. Thank you to Susan Hoyt for taking us through all of this and we will see you guys at the same time next week for for unit five. Thanks for joining us. All right, bye thank you.