WEBVTT

1
00:00:01.230 --> 00:00:05.013
<v Jonas>Let's continue with some simple string methods,</v>

2
00:00:06.780 --> 00:00:08.460
and the first two are gonna be

3
00:00:08.460 --> 00:00:10.953
for changing the case of a string.

4
00:00:14.070 --> 00:00:16.053
So that's airline.toLowerCase,

5
00:00:20.580 --> 00:00:24.450
and this doesn't require any arguments at all.

6
00:00:24.450 --> 00:00:27.210
And then we also have toUpperCase.

7
00:00:27.210 --> 00:00:29.013
And these we use all the time,

8
00:00:30.210 --> 00:00:34.590
as you will see soon in a more real-world example.

9
00:00:34.590 --> 00:00:37.770
And here you see that indeed they transform the string

10
00:00:37.770 --> 00:00:41.370
all to lowercase and to uppercase.

11
00:00:41.370 --> 00:00:44.100
And again, you can, of course, call this directly

12
00:00:44.100 --> 00:00:45.453
also on a string.

13
00:00:46.710 --> 00:00:49.473
So like this, all right.

14
00:00:52.590 --> 00:00:56.430
But now, let's use this on a more practical example

15
00:00:56.430 --> 00:00:59.643
to fix the capitalization in a passenger name.

16
00:01:03.027 --> 00:01:07.233
... in name, okay.

17
00:01:09.720 --> 00:01:11.220
So let's say that the passenger,

18
00:01:11.220 --> 00:01:14.370
when he checked in, misspelled his name,

19
00:01:14.370 --> 00:01:17.790
and so it looks like this now.

20
00:01:17.790 --> 00:01:19.980
And so this needs to be fixed,

21
00:01:19.980 --> 00:01:23.973
it should look like this, okay.

22
00:01:25.020 --> 00:01:27.600
So in order to fix it, the first step

23
00:01:27.600 --> 00:01:30.543
is usually to put everything into lowercase here.

24
00:01:31.830 --> 00:01:36.830
So const passengerLower is passenger.toLowerCase, like this.

25
00:01:44.790 --> 00:01:49.320
Okay, so basically we already have now this part here,

26
00:01:49.320 --> 00:01:51.930
and now all we need to do is to essentially

27
00:01:51.930 --> 00:01:55.860
take the first letter and then the rest of the string,

28
00:01:55.860 --> 00:01:58.203
and put these two parts back together.

29
00:02:00.210 --> 00:02:05.210
So passengerCorrect will be passengerLowercase,

30
00:02:10.080 --> 00:02:12.720
and here we only need the first letter.

31
00:02:12.720 --> 00:02:14.610
So how do we do that?

32
00:02:14.610 --> 00:02:18.930
We take the first letter by using the index zero.

33
00:02:18.930 --> 00:02:23.930
And so this one, we now convert to uppercase, all right.

34
00:02:24.450 --> 00:02:27.753
And now we simply need to add the rest of the string.

35
00:02:28.770 --> 00:02:32.160
So, again, we take passengerLower,

36
00:02:32.160 --> 00:02:34.050
and then we use the slice

37
00:02:34.050 --> 00:02:35.970
that we learned in the last lecture

38
00:02:35.970 --> 00:02:38.250
and start at position number one,

39
00:02:38.250 --> 00:02:41.700
because, remember, that will then go to index one

40
00:02:41.700 --> 00:02:45.423
and take everything until the end of the string.

41
00:02:47.250 --> 00:02:50.410
And so here we then put back together

42
00:02:51.450 --> 00:02:53.940
just the first part of the string,

43
00:02:53.940 --> 00:02:55.890
converted to uppercase here,

44
00:02:55.890 --> 00:02:58.020
and then the rest of the string

45
00:02:58.020 --> 00:03:00.783
that we already had to lowercase before.

46
00:03:03.510 --> 00:03:08.510
Okay, and indeed now it is corrected. Great.

47
00:03:10.470 --> 00:03:13.590
And of course, we could have done a function with this,

48
00:03:13.590 --> 00:03:16.560
and so maybe if you have the time you can do that.

49
00:03:16.560 --> 00:03:19.800
So just create a function that takes any passenger name

50
00:03:19.800 --> 00:03:22.770
and then returns the correct one,

51
00:03:22.770 --> 00:03:25.650
so with the fixed capitalization.

52
00:03:25.650 --> 00:03:29.640
But, anyway, I will now do another real-life example,

53
00:03:29.640 --> 00:03:34.110
which is to check a user-input email, okay.

54
00:03:34.110 --> 00:03:35.883
So check email.

55
00:03:36.780 --> 00:03:39.330
Now, this will not be really a checking,

56
00:03:39.330 --> 00:03:42.150
it will more be a comparing.

57
00:03:42.150 --> 00:03:44.313
So comparing emails.

58
00:03:46.200 --> 00:03:49.473
So let's say that we have the email of one passenger,

59
00:03:51.330 --> 00:03:55.863
so hello@jonas.io.

60
00:03:57.150 --> 00:03:59.073
But now, as the user logs in,

61
00:04:01.080 --> 00:04:06.080
so let's say loginEmail, accidentally, they do it all wrong,

62
00:04:07.740 --> 00:04:10.950
and they start with a couple of spaces here,

63
00:04:10.950 --> 00:04:15.417
and then the capitalization is all completely off like this.

64
00:04:17.610 --> 00:04:19.770
And then maybe even another space

65
00:04:19.770 --> 00:04:24.770
or even an enter character, which, remember, is \n.

66
00:04:25.140 --> 00:04:28.860
So I think we talked about that in the beginning, okay.

67
00:04:28.860 --> 00:04:31.800
But, still, this email here is actually

68
00:04:31.800 --> 00:04:35.130
still kind of correct and kind of valid.

69
00:04:35.130 --> 00:04:37.410
And so we can now still compare

70
00:04:37.410 --> 00:04:41.490
if these two are kind of the same, okay.

71
00:04:41.490 --> 00:04:45.360
So we can now try to convert this one to this one

72
00:04:45.360 --> 00:04:47.160
and then check if they are the same,

73
00:04:48.060 --> 00:04:50.850
because essentially, again, they are.

74
00:04:50.850 --> 00:04:54.180
They would be different if we had different letters here,

75
00:04:54.180 --> 00:04:56.400
then, of course, they would not be the same,

76
00:04:56.400 --> 00:04:59.580
but here it's just a matter of capitalization.

77
00:04:59.580 --> 00:05:02.760
And for emails, I believe that they are still valid

78
00:05:02.760 --> 00:05:05.040
even with the capitalization off.

79
00:05:05.040 --> 00:05:07.677
And so when we check user input like this,

80
00:05:07.677 --> 00:05:11.433
the first step is usually to convert it to lowercase.

81
00:05:12.960 --> 00:05:17.960
So lowerEmail is loginEmail.toLowerCase,

82
00:05:24.090 --> 00:05:28.050
and then we must also get rid of all the whitespace here.

83
00:05:28.050 --> 00:05:33.010
So these empty spaces and also this enter, basically, here

84
00:05:35.490 --> 00:05:37.680
also count as whitespace.

85
00:05:37.680 --> 00:05:39.963
So there is even a method for that.

86
00:05:41.220 --> 00:05:46.220
So, let's say, trimmedEmail, and so that is lowerEmail.trim.

87
00:05:52.560 --> 00:05:55.410
All right, let's just now log this

88
00:05:55.410 --> 00:05:57.060
through the console, just to see.

89
00:05:58.170 --> 00:06:01.443
And so that looks exactly like that first version.

90
00:06:02.820 --> 00:06:05.910
Now, just look closely at what we did here.

91
00:06:05.910 --> 00:06:09.900
So we called toLowerCase on this loginEmail,

92
00:06:09.900 --> 00:06:11.670
stored it to this variable,

93
00:06:11.670 --> 00:06:15.720
and then on that variable we called the trim method.

94
00:06:15.720 --> 00:06:19.650
But why do we even need this intermediate email?

95
00:06:19.650 --> 00:06:21.663
We could do this all in one step.

96
00:06:23.820 --> 00:06:26.580
So basically, we can replace all of this,

97
00:06:26.580 --> 00:06:30.453
and let's call this normalizedEmail, actually.

98
00:06:32.280 --> 00:06:35.760
And so, again, I will start from loginEmail

99
00:06:35.760 --> 00:06:37.443
and then do it all in one step.

100
00:06:39.577 --> 00:06:40.660
.toLowerCase.

101
00:06:41.940 --> 00:06:44.940
And now this is a bit similar to what we did before

102
00:06:44.940 --> 00:06:47.103
with the map set method.

103
00:06:48.420 --> 00:06:51.123
So this here will return a new string,

104
00:06:52.380 --> 00:06:55.590
and on strings we can call string methods.

105
00:06:55.590 --> 00:06:57.420
And therefore, right here,

106
00:06:57.420 --> 00:07:01.473
we can now immediately call the trim method.

107
00:07:04.770 --> 00:07:09.770
So normalizedEmail, and that should look exactly the same.

108
00:07:11.040 --> 00:07:16.040
And it does, so let's get rid of this.

109
00:07:17.370 --> 00:07:21.453
And these two I will simply leave as a comment here.

110
00:07:23.490 --> 00:07:26.520
And now, just to finish, let's actually also compare them

111
00:07:26.520 --> 00:07:28.533
for the sake of completion.

112
00:07:30.000 --> 00:07:31.860
And once again, you could do this here

113
00:07:31.860 --> 00:07:34.110
in a separate function.

114
00:07:34.110 --> 00:07:37.560
So you could do a function for this behavior

115
00:07:37.560 --> 00:07:39.600
where you pass in two emails,

116
00:07:39.600 --> 00:07:41.370
one which is the correct one

117
00:07:41.370 --> 00:07:43.650
and one which is the one to check,

118
00:07:43.650 --> 00:07:47.463
and then you could return either true or false from that.

119
00:07:48.330 --> 00:07:51.000
So again, that sounds like a good challenge

120
00:07:51.000 --> 00:07:53.103
that you can take if you want.

121
00:07:54.150 --> 00:07:57.930
And by the way, here, since ES2019,

122
00:07:57.930 --> 00:08:00.900
there's also trimStart and trimEnd,

123
00:08:00.900 --> 00:08:04.620
which, as their names say, you can use to trim whitespace

124
00:08:04.620 --> 00:08:08.463
only from the start of the string or only from the end.

125
00:08:09.510 --> 00:08:11.580
Next up, let's learn one of the most

126
00:08:11.580 --> 00:08:13.620
important thing about strings,

127
00:08:13.620 --> 00:08:16.593
which is to replace parts of strings.

128
00:08:19.110 --> 00:08:22.563
So replacing, okay.

129
00:08:23.550 --> 00:08:26.400
And we're gonna stay here again with the airlines.

130
00:08:26.400 --> 00:08:29.433
So let's say we have the price of a flight,

131
00:08:30.900 --> 00:08:35.900
and that price is for Great Britain, so let's say 288,97£.

132
00:08:42.540 --> 00:08:46.680
And you can use any other currency sign that you want here.

133
00:08:46.680 --> 00:08:48.690
What's important is that here in Europe,

134
00:08:48.690 --> 00:08:51.930
we use the comma as a decimal separator,

135
00:08:51.930 --> 00:08:56.930
unlike in the US, where you use the period, so the dot.

136
00:08:57.120 --> 00:08:59.400
And so that's actually what we're gonna do now,

137
00:08:59.400 --> 00:09:03.003
we want to compute the price in the US.

138
00:09:04.770 --> 00:09:07.890
All right, and so for that we will need to replace

139
00:09:07.890 --> 00:09:09.930
the pound with the dollar sign

140
00:09:09.930 --> 00:09:13.263
and the comma with the period.

141
00:09:14.460 --> 00:09:17.470
So that's easy enough, priceGB.replace,

142
00:09:21.150 --> 00:09:23.490
and now here two arguments.

143
00:09:23.490 --> 00:09:26.193
The first one is the one we want to replace,

144
00:09:27.090 --> 00:09:29.610
and let's start here with the pound sign.

145
00:09:29.610 --> 00:09:31.890
And the second argument is the string

146
00:09:31.890 --> 00:09:34.263
that will replace the first one.

147
00:09:38.280 --> 00:09:40.713
So let's take a look, priceUS.

148
00:09:43.410 --> 00:09:45.420
And so that already worked.

149
00:09:45.420 --> 00:09:48.543
And now we need to replace also the comma with the period.

150
00:09:49.530 --> 00:09:52.230
So we could create another variable now,

151
00:09:52.230 --> 00:09:55.020
but instead we will do chaining again,

152
00:09:55.020 --> 00:09:56.670
just like we did before.

153
00:09:56.670 --> 00:10:01.350
And for the same reason, because this returns a string.

154
00:10:01.350 --> 00:10:02.550
And so, on that string

155
00:10:02.550 --> 00:10:07.410
we will immediately call the next replace method.

156
00:10:07.410 --> 00:10:12.093
And now, we are replacing the comma with the dot.

157
00:10:12.960 --> 00:10:16.143
And so, indeed, now we have the price in US.

158
00:10:18.780 --> 00:10:22.530
But, indeed, we can also replace entire words,

159
00:10:22.530 --> 00:10:25.140
not just single characters.

160
00:10:25.140 --> 00:10:26.820
So let's create an announcement

161
00:10:26.820 --> 00:10:30.007
that you would typically hear at the airport, like,

162
00:10:30.007 --> 00:10:35.007
"All passengers come to boarding door 23. Boarding door 23."

163
00:10:43.050 --> 00:10:47.250
However, usually, it is called a gate and not door,

164
00:10:47.250 --> 00:10:48.930
and so, let's replace that

165
00:10:48.930 --> 00:10:51.453
and log the results to the console immediately,

166
00:10:53.190 --> 00:10:56.340
because, just like the other method that we studied,

167
00:10:56.340 --> 00:10:59.370
replace also creates a brand-new string.

168
00:10:59.370 --> 00:11:02.370
It doesn't mutate the original one.

169
00:11:02.370 --> 00:11:03.900
And so here, it's the same,

170
00:11:03.900 --> 00:11:07.593
and so we need to log the actual result to the console.

171
00:11:09.210 --> 00:11:14.210
So, replace door with gate.

172
00:11:15.660 --> 00:11:20.463
Here it's boarding, and now let's check it out here.

173
00:11:21.960 --> 00:11:23.820
So here, boarding gate,

174
00:11:23.820 --> 00:11:27.870
but then here you actually still have boarding door.

175
00:11:27.870 --> 00:11:30.390
And so this replace only replaced

176
00:11:30.390 --> 00:11:34.023
the first occurrence of this search string here.

177
00:11:35.490 --> 00:11:37.560
And actually, that's completely normal,

178
00:11:37.560 --> 00:11:40.770
that's just how the replace method works.

179
00:11:40.770 --> 00:11:43.770
So, again, this method will only replace

180
00:11:43.770 --> 00:11:48.060
the very first occurrence of this search string.

181
00:11:48.060 --> 00:11:49.830
So in this case the door,

182
00:11:49.830 --> 00:11:52.770
but the rest of them will simply stay the same,

183
00:11:52.770 --> 00:11:55.200
so they will not get updated.

184
00:11:55.200 --> 00:12:00.150
But fortunately for us, there's also the replaceAll method,

185
00:12:00.150 --> 00:12:01.830
which, as the name says,

186
00:12:01.830 --> 00:12:05.070
will actually replace all the occurrences

187
00:12:05.070 --> 00:12:06.810
of the search string.

188
00:12:06.810 --> 00:12:10.290
So in this case, it will replace all the doors

189
00:12:10.290 --> 00:12:12.663
with gates, basically.

190
00:12:13.710 --> 00:12:16.740
Now, at the time that I was recording this video

191
00:12:16.740 --> 00:12:20.280
this method wasn't available in JavaScript yet,

192
00:12:20.280 --> 00:12:23.610
and so that's why here we get this error.

193
00:12:23.610 --> 00:12:25.440
But never mind about this,

194
00:12:25.440 --> 00:12:28.020
because now that you're watching this video

195
00:12:28.020 --> 00:12:29.760
this will actually work,

196
00:12:29.760 --> 00:12:31.950
and so you should definitely go ahead

197
00:12:31.950 --> 00:12:34.500
and use this solution right here,

198
00:12:34.500 --> 00:12:36.600
so, the replaceAll method,

199
00:12:36.600 --> 00:12:39.660
whenever you need to replace multiple occurrences

200
00:12:39.660 --> 00:12:44.160
of a certain substring inside the bigger string.

201
00:12:44.160 --> 00:12:48.030
Now, besides this solution, there's also another solution

202
00:12:48.030 --> 00:12:51.600
that was available before we had the replaceAll method,

203
00:12:51.600 --> 00:12:54.480
which involves using a regular expression,

204
00:12:54.480 --> 00:12:57.510
which is what I'm going to show you next.

205
00:12:57.510 --> 00:13:00.990
Now, regular expressions are one of the most complex

206
00:13:00.990 --> 00:13:03.510
and confusing topics of programming,

207
00:13:03.510 --> 00:13:05.190
but for now we are just gonna use

208
00:13:05.190 --> 00:13:09.840
a very simple, regular expression to tell the replace method

209
00:13:09.840 --> 00:13:11.520
that it should actually target

210
00:13:11.520 --> 00:13:16.143
all the occurrences of door here and not just the first one.

211
00:13:17.250 --> 00:13:18.963
So let's again copy this here.

212
00:13:20.070 --> 00:13:22.530
And then, to create a regular expression,

213
00:13:22.530 --> 00:13:25.980
we need to write the string between slashes,

214
00:13:25.980 --> 00:13:27.693
so not between quotes.

215
00:13:29.910 --> 00:13:31.560
So it turned yellow here, again,

216
00:13:31.560 --> 00:13:34.800
which means that it's some kind of string,

217
00:13:34.800 --> 00:13:38.190
but it is now a so-called regular expression.

218
00:13:38.190 --> 00:13:39.960
Then in this case, all we want to do

219
00:13:39.960 --> 00:13:44.960
with this regular expression is to add this g flag here,

220
00:13:45.000 --> 00:13:47.460
and this stands for global.

221
00:13:47.460 --> 00:13:49.530
And that's actually it.

222
00:13:49.530 --> 00:13:52.860
So right now, all the occurrences will be targeted,

223
00:13:52.860 --> 00:13:56.433
and so we replaced gate here and here.

224
00:13:57.420 --> 00:14:01.050
All right, and just as a side note here,

225
00:14:01.050 --> 00:14:03.810
once more, the replace method is, of course,

226
00:14:03.810 --> 00:14:05.880
also case-sensitive.

227
00:14:05.880 --> 00:14:09.153
So just like all of the other string methods are.

228
00:14:10.080 --> 00:14:13.650
Okay, and now as a final topic of this lecture,

229
00:14:13.650 --> 00:14:17.163
there are three simple methods that return booleans.

230
00:14:18.633 --> 00:14:21.720
So, booleans, okay.

231
00:14:21.720 --> 00:14:26.670
And these methods are includes startsWith and endsWith,

232
00:14:26.670 --> 00:14:29.973
so let's create a new plane here,

233
00:14:31.530 --> 00:14:34.023
and that's gonna be the A320neo.

234
00:14:36.390 --> 00:14:39.963
And I'm just missing here the assignment.

235
00:14:41.430 --> 00:14:43.770
And now, we can simply use includes,

236
00:14:43.770 --> 00:14:46.833
just like we can in arrays one more time.

237
00:14:48.990 --> 00:14:52.830
So they have a very similar structure here

238
00:14:52.830 --> 00:14:56.670
in terms of methods that we can use on them.

239
00:14:56.670 --> 00:14:59.040
So, includes, and let's test

240
00:14:59.040 --> 00:15:02.373
if it includes the string A320.

241
00:15:04.320 --> 00:15:06.750
And indeed, it does.

242
00:15:06.750 --> 00:15:10.650
So this airplane here is the Airbus A320neo,

243
00:15:10.650 --> 00:15:13.653
but it still includes just the A320.

244
00:15:15.120 --> 00:15:17.703
Now, let's say if it includes Boeing,

245
00:15:18.930 --> 00:15:21.153
and of course it doesn't.

246
00:15:22.590 --> 00:15:27.590
And now there's another one, which is the startsWith.

247
00:15:30.341 --> 00:15:33.143
And this one is also actually very much used,

248
00:15:34.050 --> 00:15:36.153
I remember using it very recently.

249
00:15:37.230 --> 00:15:41.670
And so in this case here it is false, all right.

250
00:15:41.670 --> 00:15:45.300
But then if we change this here to Airbus,

251
00:15:45.300 --> 00:15:47.493
then it is indeed true.

252
00:15:48.840 --> 00:15:51.570
So these three letters here

253
00:15:51.570 --> 00:15:54.330
are indeed the first three also here,

254
00:15:54.330 --> 00:15:56.853
so it doesn't have to match the entire word.

255
00:15:57.690 --> 00:16:01.050
So just Ai would also be true,

256
00:16:01.050 --> 00:16:06.050
but Aib, let's say, would then be false,

257
00:16:06.300 --> 00:16:08.310
because, of course, the string does not

258
00:16:08.310 --> 00:16:10.740
start with these three letters.

259
00:16:10.740 --> 00:16:13.743
With Airb, then it would again be true.

260
00:16:15.390 --> 00:16:18.333
And of course this A320 is also still true,

261
00:16:19.200 --> 00:16:21.930
as long as it is somewhere in the string.

262
00:16:21.930 --> 00:16:24.273
So now it's somehow here in the middle.

263
00:16:25.680 --> 00:16:29.520
So let's try something very simple here.

264
00:16:29.520 --> 00:16:31.710
So let's say that we want to check

265
00:16:31.710 --> 00:16:36.540
if the current plane is part of the new Airbus family.

266
00:16:36.540 --> 00:16:39.330
And so all we need to do to check that

267
00:16:39.330 --> 00:16:43.323
is to see if the plane name starts with Airbus,

268
00:16:44.460 --> 00:16:46.503
and we can already confirm that it is.

269
00:16:49.140 --> 00:16:54.140
And we also need to check if it ends with neo,

270
00:16:55.350 --> 00:16:57.240
because that means that it's part

271
00:16:57.240 --> 00:17:00.810
of the new Airbus family.

272
00:17:00.810 --> 00:17:02.673
And so we can also use endsWith.

273
00:17:05.760 --> 00:17:08.610
So, as always, these methods here

274
00:17:08.610 --> 00:17:11.520
that return booleans are especially helpful

275
00:17:11.520 --> 00:17:13.473
for conditionals like this,

276
00:17:16.260 --> 00:17:20.793
Part of the NEW Airbus family.

277
00:17:22.410 --> 00:17:24.513
And indeed, this one here is.

278
00:17:25.380 --> 00:17:29.490
But, of course, if it was just a regular A320,

279
00:17:29.490 --> 00:17:32.583
then that would not get logged to the console.

280
00:17:34.050 --> 00:17:36.480
So whenever you need to take some decision

281
00:17:36.480 --> 00:17:39.000
based on the contents of the string,

282
00:17:39.000 --> 00:17:43.170
these three methods are very, very helpful.

283
00:17:43.170 --> 00:17:45.640
And let's now actually practice that a little bit

284
00:17:46.980 --> 00:17:48.153
with some kinds of-

285
00:17:48.990 --> 00:17:51.780
yeah, we can say, a practice exercise.

286
00:17:51.780 --> 00:17:54.330
And so here we want to check if the baggage

287
00:17:54.330 --> 00:17:56.190
of a certain passenger

288
00:17:56.190 --> 00:17:58.833
is basically allowed to be checked in,

289
00:18:00.330 --> 00:18:02.223
so to be allowed on the plane.

290
00:18:03.060 --> 00:18:07.530
So, checkBaggage function, and then here we get the items,

291
00:18:12.300 --> 00:18:14.430
and let me again first call the function

292
00:18:14.430 --> 00:18:15.753
to show you what I mean.

293
00:18:17.970 --> 00:18:21.420
So basically, the passenger here says what they have,

294
00:18:21.420 --> 00:18:26.420
so, "I have a laptop, some food, and a pocket knife."

295
00:18:29.970 --> 00:18:33.093
Then let's call this again and say,

296
00:18:34.918 --> 00:18:38.007
"I have some socks and a camera."

297
00:18:39.180 --> 00:18:42.577
And then, let's call it a third time with the string note,

298
00:18:42.577 --> 00:18:47.577
"Got some snacks and a gun for protection."

299
00:18:49.500 --> 00:18:54.500
Okay, so maybe some passenger would bring a gun to a plane,

300
00:18:55.620 --> 00:18:57.390
but so now let's make sure

301
00:18:57.390 --> 00:19:00.210
they will not get aboard the plane.

302
00:19:00.210 --> 00:19:03.123
And, actually, let's change some things here.

303
00:19:04.200 --> 00:19:05.610
So let's make this uppercase,

304
00:19:05.610 --> 00:19:08.760
let's say this person likes to write

305
00:19:08.760 --> 00:19:10.293
uppercase for some reason.

306
00:19:12.750 --> 00:19:16.200
And so this is important to show you, once again,

307
00:19:16.200 --> 00:19:18.570
that when we receive input from a user

308
00:19:18.570 --> 00:19:20.370
we usually always start

309
00:19:20.370 --> 00:19:23.640
by putting everything into lowercase,

310
00:19:23.640 --> 00:19:25.470
because that makes it a lot easier

311
00:19:25.470 --> 00:19:27.333
to then compare it to something.

312
00:19:29.589 --> 00:19:31.563
(indistinct) say baggage here.

313
00:19:33.030 --> 00:19:36.163
And so, baggage is basically items.toLowerCase.

314
00:19:37.500 --> 00:19:39.153
So this one we use all the time.

315
00:19:40.740 --> 00:19:42.690
And now we can just check if the baggage

316
00:19:42.690 --> 00:19:45.630
includes a knife or a gun,

317
00:19:45.630 --> 00:19:48.663
and in that case the person is not allowed on board.

318
00:19:50.310 --> 00:19:54.213
So, if baggage.includes,

319
00:19:55.650 --> 00:19:59.820
and so here is that method again, which returns a boolean.

320
00:19:59.820 --> 00:20:04.820
So, if it includes knife or if it-

321
00:20:06.480 --> 00:20:11.480
so baggage includes a gun, then we say,

322
00:20:16.957 --> 00:20:21.957
"You are not allowed on board."

323
00:20:24.660 --> 00:20:29.660
else, let's log "Welcome aboard."

324
00:20:33.840 --> 00:20:36.990
And so now let's see here why it is so important

325
00:20:36.990 --> 00:20:39.783
to convert everything first to lowercase.

326
00:20:40.710 --> 00:20:44.490
So in this example here, this first person has knife,

327
00:20:44.490 --> 00:20:46.680
but with an uppercase.

328
00:20:46.680 --> 00:20:50.160
And so if we didn't convert this to lowercase,

329
00:20:50.160 --> 00:20:53.100
then this includes here would be false,

330
00:20:53.100 --> 00:20:55.680
because the lowercase knife is different

331
00:20:55.680 --> 00:20:57.153
than the uppercase knife.

332
00:20:58.530 --> 00:21:02.640
Okay, so let's see the result.

333
00:21:02.640 --> 00:21:05.190
And so indeed, this person has a knife

334
00:21:05.190 --> 00:21:07.230
so they're not allowed.

335
00:21:07.230 --> 00:21:10.680
This person here is fine, and then this one has a gun,

336
00:21:10.680 --> 00:21:13.590
and so, of course, they're also not allowed.

337
00:21:13.590 --> 00:21:17.190
But now, if we took away this here,

338
00:21:17.190 --> 00:21:20.073
well then our code is not really gonna work,

339
00:21:21.540 --> 00:21:25.653
so let's just delete this part for now.

340
00:21:27.030 --> 00:21:30.030
So if we didn't have the toLowerCase,

341
00:21:30.030 --> 00:21:33.510
then the first person would also be "Welcome aboard".

342
00:21:33.510 --> 00:21:37.080
And again, that's because knife here, uppercase,

343
00:21:37.080 --> 00:21:39.000
is different from this knife.

344
00:21:39.000 --> 00:21:42.870
And so then we would have to check for all the variations,

345
00:21:42.870 --> 00:21:47.870
like knife like this, or this knife, or even this.

346
00:21:48.840 --> 00:21:51.510
So every possible variation.

347
00:21:51.510 --> 00:21:54.090
And so that would be highly impractical,

348
00:21:54.090 --> 00:21:56.643
and so we just turn everything to lowercase.

349
00:21:58.530 --> 00:22:01.830
So, again, so that we can then easily compare it

350
00:22:01.830 --> 00:22:05.733
with one standard, which is this and this.

351
00:22:07.410 --> 00:22:09.630
All right, perfect.

352
00:22:09.630 --> 00:22:13.080
So that was another fun lecture, if you ask me,

353
00:22:13.080 --> 00:22:15.840
and I hope you are feeling the same.

354
00:22:15.840 --> 00:22:17.580
Now it's time for a break,

355
00:22:17.580 --> 00:22:20.403
and I'll see you back here in the next video.

