1 00:00:01,690 --> 00:00:05,870 OK, here we are back in VS code, so let's work up an example. 2 00:00:06,790 --> 00:00:11,400 So in this example, we're going through a menu and we're ordering something off the menu. 3 00:00:11,920 --> 00:00:16,960 So at the end, we want to check with the user and make sure that they don't want to order something 4 00:00:16,960 --> 00:00:17,430 extra. 5 00:00:18,280 --> 00:00:19,870 So we'll say something like, 6 00:00:23,170 --> 00:00:26,770 let's prompt or not prompt. 7 00:00:27,190 --> 00:00:32,270 What answer equals prompt on? 8 00:00:39,060 --> 00:00:41,430 What size price? 9 00:00:44,190 --> 00:00:45,120 Would you like. 10 00:00:49,180 --> 00:01:02,760 And I've got the team take to work very well, and then down here will say, yes, answer equals small, 11 00:01:05,410 --> 00:01:06,400 we'll say 12 00:01:10,600 --> 00:01:12,690 I'm going to do this all night in the council. 13 00:01:12,730 --> 00:01:20,950 So we'll say answer equals I will say confirm this time. 14 00:01:22,000 --> 00:01:28,090 Confirm small is not very much. 15 00:01:29,290 --> 00:01:30,680 Are you sure? 16 00:01:33,970 --> 00:01:41,290 And if answer is true, will go on otherwise then we'll ask them what size would you like that. 17 00:01:45,620 --> 00:01:47,900 So absolutely false in this case. 18 00:01:47,930 --> 00:01:50,050 We'll say not answer. 19 00:01:51,170 --> 00:01:57,570 And by the way, I should be using a triple equals sign up here to check the type as well. 20 00:01:59,420 --> 00:02:00,950 So we'll say, if not, answer. 21 00:02:04,270 --> 00:02:07,840 We'll say answer equals prompt, 22 00:02:11,950 --> 00:02:14,860 would we go confirm? 23 00:02:19,150 --> 00:02:22,030 Would you like large? 24 00:02:26,440 --> 00:02:39,080 And then we'll say, let's see here will say, well, credit variables say a lot of fry size of the 25 00:02:39,100 --> 00:02:49,750 Y equals zero, where zero means they don't want any fries, one too small to medium and three is large. 26 00:02:51,370 --> 00:02:54,510 And so then we'll say, would you like large? 27 00:02:54,520 --> 00:02:56,470 They do want a large B three. 28 00:02:57,370 --> 00:03:02,060 Otherwise it's going to be two because the only choice is medium. 29 00:03:03,370 --> 00:03:06,730 So we'll say if you answer. 30 00:03:10,170 --> 00:03:17,430 And then we'll say fry size equals three 31 00:03:20,090 --> 00:03:32,490 else, fry size equals two, and then the all the way back here where we didn't confirm this, it's 32 00:03:32,490 --> 00:03:37,830 always better to have a positive answer or positive checks are going to change this to true. 33 00:03:38,640 --> 00:03:42,120 And all this down here will make into a fall or into an else. 34 00:03:44,190 --> 00:03:52,590 So if they are sure they want small, we'll make the prices be three, I'm sorry, one. 35 00:03:54,420 --> 00:04:03,060 And then also I will say we won't bother to ask them if they say medium or if they say large, we'll 36 00:04:03,060 --> 00:04:04,440 just assume that that's OK. 37 00:04:05,610 --> 00:04:15,750 So we'll say, oh, if answer equals medium. 38 00:04:22,050 --> 00:04:25,200 Frame size equals to. 39 00:04:29,350 --> 00:04:37,900 Else, what would you say else, there's no other choices else prices equals three. 40 00:04:40,920 --> 00:04:43,350 And then down here at the bottom, we'll just toss up an alert. 41 00:04:46,430 --> 00:04:53,810 And we'll deal with the templating your price size is. 42 00:04:58,560 --> 00:04:59,220 Process. 43 00:05:00,120 --> 00:05:03,810 All right, so we got a little program here that does a couple of things. 44 00:05:04,380 --> 00:05:08,220 So let's go ahead and run it and. 45 00:05:15,200 --> 00:05:16,830 So what size fries would you like? 46 00:05:17,780 --> 00:05:25,980 So let's just say a large quick, OK, tossed out there, your fries houses three. 47 00:05:27,270 --> 00:05:28,160 Let's run it again. 48 00:05:29,360 --> 00:05:31,450 We say medium. 49 00:05:32,270 --> 00:05:33,950 It says your price rises, too. 50 00:05:35,930 --> 00:05:42,790 If we say small, small is not very much. 51 00:05:42,800 --> 00:05:43,690 Are you sure? 52 00:05:45,260 --> 00:05:49,130 We will say cancel means not sure in this case. 53 00:05:50,090 --> 00:05:55,340 Would you like a large number or a large difference sizes too. 54 00:05:56,120 --> 00:06:03,650 So you can see a confirm is a little bit a little bit difficult on that as far as the prompt. 55 00:06:04,070 --> 00:06:05,010 Can you change the prompt? 56 00:06:05,030 --> 00:06:06,050 I don't remember now. 57 00:06:06,440 --> 00:06:07,190 It doesn't look like. 58 00:06:09,440 --> 00:06:16,130 All right, so we've got this little thing in here where we're checking the prices and it can be small, 59 00:06:16,130 --> 00:06:16,800 medium or large. 60 00:06:16,820 --> 00:06:22,820 Now, there's a little problem here, which is that if you don't type in the answer. 61 00:06:22,820 --> 00:06:27,150 Exactly, it's going to give you well, it's probably going to give you large. 62 00:06:27,170 --> 00:06:34,070 So if I say I want small without an uppercase, yes, it's going to fall all the way through to the 63 00:06:34,070 --> 00:06:37,880 house and say, hey, you wanted a large which is maybe not what the user wanted it. 64 00:06:37,880 --> 00:06:38,200 Right. 65 00:06:39,290 --> 00:06:44,150 So we can build in a little bit more better air checking into this, too. 66 00:06:44,150 --> 00:06:48,060 So they only give the answer that that they're supposed to give. 67 00:06:48,980 --> 00:06:56,030 So let's do that a little bit differently and say, what size fries would you like? 68 00:06:59,840 --> 00:07:02,930 And we'll give them more limited choices of what they can enter. 69 00:07:03,620 --> 00:07:08,210 So we'll say as equals more 70 00:07:11,390 --> 00:07:19,680 and equals medium now equals large. 71 00:07:22,460 --> 00:07:22,820 All right. 72 00:07:23,900 --> 00:07:28,300 So we're going to have them enter the S, M or L instead. 73 00:07:28,310 --> 00:07:39,260 So let's change this to S, let's change this to M and let's go ahead and change this. 74 00:07:39,410 --> 00:07:40,700 So we do the check. 75 00:07:41,460 --> 00:07:46,610 The answer equals L. 76 00:07:49,170 --> 00:07:52,730 All right, so let's try that and see what happens. 77 00:07:58,930 --> 00:08:04,530 What size, Farai, would you like as equal, small and medium, Alekos, large, yes. 78 00:08:06,450 --> 00:08:10,590 Your friend has a zero because if all the way through and it didn't find anything, so there are no 79 00:08:10,590 --> 00:08:11,020 fries. 80 00:08:11,910 --> 00:08:18,790 So our first problem is that our answers equals an uppercase value. 81 00:08:19,200 --> 00:08:23,250 So one way we can handle this is by using an R so we can say or 82 00:08:25,680 --> 00:08:30,210 answer equals a little less 83 00:08:33,180 --> 00:08:34,220 and then think that here. 84 00:08:34,230 --> 00:08:35,640 But I'm not going to change it for right now. 85 00:08:38,930 --> 00:08:43,130 Right now, I find a little less that's going to go into the small logic. 86 00:08:43,520 --> 00:08:44,390 Are you sure? 87 00:08:45,140 --> 00:08:47,120 OK, Fry says one we order a large. 88 00:08:51,250 --> 00:08:57,450 OK, another way to handle this would be with a switch statement instead of these ifs. 89 00:08:58,040 --> 00:09:02,860 The problem with a bunch of this when you have different cases is it starts getting complicated. 90 00:09:03,260 --> 00:09:08,710 Switch statement will make it a little bit simpler so you can do any switch statement with ifs. 91 00:09:09,340 --> 00:09:13,670 But switch statement is better if you have a certain set of answers that you're going to get. 92 00:09:14,710 --> 00:09:15,880 So we'll say switch 93 00:09:18,220 --> 00:09:18,940 answer. 94 00:09:23,730 --> 00:09:25,600 And then here we'll say case. 95 00:09:29,900 --> 00:09:30,590 Yes, 96 00:09:34,700 --> 00:09:35,980 case a little less. 97 00:09:37,220 --> 00:09:38,450 And when you get a curly brace. 98 00:09:42,010 --> 00:09:50,560 And we get down in the end of this and we say break and then down here case and. 99 00:09:53,800 --> 00:10:06,070 Case little in and we get rid of this stuff and we also want to get rid of this extra curly brace and 100 00:10:06,070 --> 00:10:09,010 we'll get rid of this stuff and at the end of this Christmas break, 101 00:10:11,860 --> 00:10:16,330 and then instead of this, we want to say. 102 00:10:18,970 --> 00:10:22,450 Case, Al. 103 00:10:25,560 --> 00:10:35,760 Case a little while and at the end of this, we want to say break and then we going say default. 104 00:10:43,710 --> 00:10:46,530 No fries ordered, 105 00:10:49,590 --> 00:10:51,300 and then we ended up with the curly fries. 106 00:10:52,150 --> 00:10:58,020 Now a lot of times Vaskov will organize your coat for you when you finalize a curly brace, but it did 107 00:10:58,030 --> 00:10:58,980 do it in this case. 108 00:10:59,460 --> 00:11:04,830 So I'm going to give you a shortcut to reorganize all your code so you lose you hold down the control 109 00:11:04,830 --> 00:11:05,310 key. 110 00:11:05,640 --> 00:11:06,510 This is on Windows. 111 00:11:06,510 --> 00:11:13,890 It might be different on a Macintosh or Linux, but you do control a which is to select all and then 112 00:11:13,890 --> 00:11:19,350 control still holding down the control k f and reformats your code. 113 00:11:20,100 --> 00:11:24,230 So now everything is indented correctly. 114 00:11:25,020 --> 00:11:27,800 So here we have a case statement that does this. 115 00:11:28,260 --> 00:11:29,280 So that's kind of nice. 116 00:11:29,670 --> 00:11:33,780 So let's save that and let's run. 117 00:11:33,780 --> 00:11:35,880 It was a surprise. 118 00:11:35,910 --> 00:11:40,800 Would you like to say a little as small as. 119 00:11:40,800 --> 00:11:41,390 Not very much. 120 00:11:41,400 --> 00:11:42,060 Are you sure. 121 00:11:42,070 --> 00:11:45,660 I say cancel and it says, would you like large? 122 00:11:45,660 --> 00:11:47,430 Why is it asking me would you like large? 123 00:11:50,930 --> 00:11:57,680 Oh, oh, because I said that I don't want the small, so we'll say, OK, your price has just three, 124 00:11:58,100 --> 00:11:58,700 that's fine. 125 00:11:59,840 --> 00:12:04,850 So this solves it, but we can make it even a little bit simpler. 126 00:12:05,390 --> 00:12:10,910 If we said, if you recall correctly, on the two string, there's a two on the on the string, there's 127 00:12:10,910 --> 00:12:16,280 a two upper second say to upper case. 128 00:12:18,170 --> 00:12:24,230 So we we change the diaper case so we can get rid of the little the little characters. 129 00:12:25,970 --> 00:12:27,890 And that makes our program a little bit simpler. 130 00:12:27,890 --> 00:12:32,650 So all we have is S, M and L and no fries ordered. 131 00:12:35,330 --> 00:12:37,070 So it should work exactly the same 132 00:12:40,130 --> 00:12:45,230 medium and taking a lower case m different sizes too. 133 00:12:46,040 --> 00:12:51,200 OK, let's thing, let's use the ternary operator to handle the the size down here. 134 00:12:51,920 --> 00:12:56,720 So we're going to embed a couple of things and we'll do it as a separate statement. 135 00:12:58,670 --> 00:13:02,010 We'll say let's bring in a conflict because we're not going to change it. 136 00:13:02,390 --> 00:13:07,100 Costed Fahri size name equals. 137 00:13:07,670 --> 00:13:10,250 So the price size is one, it's large. 138 00:13:10,790 --> 00:13:23,030 So we'll say fry size properly equals one then large and then we could say else something else. 139 00:13:23,030 --> 00:13:28,560 But we need to check if it's two or three and we also need to check on the zero. 140 00:13:28,850 --> 00:13:32,900 So this can be sort of the complicated ternary. 141 00:13:32,900 --> 00:13:41,150 So let's just start with this and say if it's one that is large, otherwise it's medium and that's not 142 00:13:41,150 --> 00:13:41,510 right. 143 00:13:41,510 --> 00:13:44,090 But we'll make it more complicated in just a second. 144 00:13:49,240 --> 00:14:02,530 So we'll say you are a large Frazetta three, and that's because I did not put the price his name in 145 00:14:02,530 --> 00:14:02,800 here. 146 00:14:13,370 --> 00:14:26,210 So if assizes million, let's say I've got it backwards, largest three. 147 00:14:30,020 --> 00:14:31,040 Let's try one more time 148 00:14:34,550 --> 00:14:36,110 right now. 149 00:14:38,030 --> 00:14:40,460 If ISIS is like anything else better, it's can be media. 150 00:14:41,360 --> 00:14:42,290 So fighter. 151 00:14:43,740 --> 00:14:51,800 Q Let's just say, I guess the president, because it goes the alert first and then once he's done with 152 00:14:51,800 --> 00:14:53,630 that, it says your privatizes media. 153 00:14:54,170 --> 00:14:54,530 All right. 154 00:14:55,160 --> 00:15:05,000 So one thing we can do since we get this alert here, if we don't get a good process, is we can say 155 00:15:05,720 --> 00:15:18,370 if Fahri size is greater than or equal to one and Frys size is less than or equal to three. 156 00:15:18,740 --> 00:15:23,520 So that way we won't get a double message on that. 157 00:15:24,860 --> 00:15:26,830 And again, you can see it in dance. 158 00:15:26,830 --> 00:15:32,250 So I'm just going to do the control AK and it will reorganize everything. 159 00:15:33,470 --> 00:15:38,240 So now we're only doing this for the large and medium. 160 00:15:38,540 --> 00:15:42,470 So on the medium side, what we'll do is go down to a new line. 161 00:15:45,020 --> 00:15:45,640 Why do that? 162 00:15:45,650 --> 00:15:47,690 I'd like to indent so on. 163 00:15:47,690 --> 00:16:00,710 The new line will say if the fray size equals to that, it's a medium, otherwise small. 164 00:16:02,500 --> 00:16:07,630 And when you start doing this with the ternary operator, it's probably better put parentheses around 165 00:16:07,640 --> 00:16:10,460 their here so it doesn't mistake you. 166 00:16:10,460 --> 00:16:16,070 Don't make a mistake on what you're doing now with it only gets grouped together. 167 00:16:17,510 --> 00:16:17,900 All right. 168 00:16:23,900 --> 00:16:24,610 Is that right? 169 00:16:24,660 --> 00:16:35,260 How the world will say to you, why are we getting no prize or because I said to get my own rules, 170 00:16:35,740 --> 00:16:43,490 I am different sizes, medium sized again and small. 171 00:16:45,340 --> 00:16:46,220 Are you sure? 172 00:16:46,620 --> 00:16:52,000 OK, for our size as small as brown one more time or small. 173 00:16:53,410 --> 00:16:54,290 Are you sure? 174 00:16:54,490 --> 00:16:55,030 No. 175 00:16:55,030 --> 00:16:58,330 We like a large size is large. 176 00:16:59,410 --> 00:17:07,570 And again, if we enter a bad entry like, you know, fries ordered and it's not going to give us the 177 00:17:07,570 --> 00:17:08,710 second message this time. 178 00:17:11,020 --> 00:17:19,330 So anyway, that is an introduction to the conditionals using relational operators and logical operators, 179 00:17:19,870 --> 00:17:23,110 and that really helps build out our programming examples.