All language subtitles for 19. Logical Operators

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranรฎ)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu

Original subtitles

1 1

Let's now return to our code 2

2

and learn how logical operators work in JavaScript. 3

3

And let's actually use the Boolean variables 4

4

from the last lecture. 5

5

So the one about having a drivers license 6

6

and having good vision. 7

7

So, we are gonna create a variable for each of them. 8

8

And the first one will be has drivers license 9

9

and let's start by setting it to true. 10

10

And remember that this one was variable A. 11

11

And then let's create has good vision 12

12

and also, let's initialize it with true. 13

13

So these were the two A and B variables 14

14

that we used in the last lecture as an example. 15

15

And so it's a good idea to use these here as well. 16

16

Okay, but now let's get started with the end 17

17

and or operators. 18

18

So let's log to the console, of using the end operator 19

19

on these two variables. 20

20

So has drivers license 21

21

and now the end operator in JavaScript is this one. 22

22

So it is we can combine two logical values. 23

23

So has drivers license and has good vision. 24

24

So let's see what the result will be. 25

25

So this one is true, right? 26

26

And this one is true as well. 27

27

So the result of true and true, should be true, right? 28

28

So let's see and yes, so that works. 29

29

But now, of course, we will change one of them to false. 30

30

So remember, the result of true and false will be false, 31

31

because it's enough for one variable to be false 32

32

for the result of the operation to be false. 33

33

And so here, we can now confirm that 34

34

and indeed, that is the result. 35

35

But now let's see what it would look like 36

36

with the OR operator. 37

37

So I just copy this and paste it here. 38

38

Now, instead of end we use OR and that looks like this. 39

39

So again, true or false. 40

40

What do you think it will be? 41

41

Remember from the last lecture and the result is true. 42

42

So it's enough for one of the variables to be true 43

43

for the whole operation to become true. 44

44

So I hope that's nothing new at this point. 45

45

And of course, finally we can also use the NOT operator 46

46

to basically invert one of the values. 47

47

And the NOT operator in JavaScript is the exclamation mark. 48

48

So not has driver's license will become, 49

49

so it will change from true to false. 50

50

All right, and now since we know how all of this works, 51

51

we can use these variables to take a decision. 52

52

So let's say that we want to determine 53

53

whether Sarah should drive or not. 54

54

So let's create a new Boolean variable and use the others 55

55

to determine that. 56

56

So let's say should drive 57

57

and our model is that Sarah should drive, 58

58

if she has a driver's license 59

59

and at the same time has good vision, okay? 60

60

And so as I mentioned in the last lecture, 61

61

we can now use these Boolean variables, 62

62

and this Boolean logic to model complex situations. 63

63

And this one is actually pretty simple, 64

64

but we will take it up a notch by the end of this lecture. 65

65

So remember, model is that she has a driver's license, 66

66

and that she has good vision. 67

67

Okay, and now we can use this variable 68

68

to finally take the decision. 69

69

So let's then use this Boolean variable here and say, 70

70

if she should drive, then lock to the console. 71

71

Sarah is able to drive 72

72

and if not, 73

73

just log someone else 74

74

should derive. 75

75

Now, okay, and actually we can put the condition right here 76

76

in the IF condition. 77

77

So this was just to show you a little bit 78

78

the thought process. 79

79

But as I mentioned earlier, 80

80

we usually create the condition right here 81

81

in the IF statement. 82

82

So give it a safe and now let's run it and the result is, 83

83

someone else should drive. 84

84

So that is because has good vision is false, 85

85

and so our condition of has driver's license 86

86

and has good vision is not true. 87

87

Because it's only true in case that both of them are true, 88

88

as you already know by now. 89

89

So this one is false right now. 90

90

And so therefore the else block will be executed. 91

91

But of course, we can change it once more. 92

92

And so right now, both of them are true. 93

93

So has driver's license true and has good vision true. 94

94

So true and true, is true and so Sarah is able to drive. 95

95

Let's check that and indeed, great. 96

96

And but this one working now perfectly, 97

97

let's take it to the next level 98

98

and add another Boolean variable here. 99

99

So, let's now also add is tired. 100

100

And let's set it to true as well. 101

101

So we can say that this is our variable C. 102

102

So to use more than two variables with, for example, 103

103

the end operator, let's just go ahead and copy this one. 104

104

So if you want to say has driver's license 105

105

or has good vision or is tired. 106

106

All you have to do is to add another OR operator here, 107

107

just like you would add another plus 108

108

or another minus operator. 109

109

And the result of this should of course, be true, 110

110

because while all of them are true. 111

111

And indeed, it is. 112

112

And if we set them all to end, 113

113

then it is also true, because all of them are true. 114

114

And if we set this one to false, 115

115

then as you can guess the result will be false. 116

116

And that is because as I explained in the last lecture, 117

117

it's enough for one of the operands to be false 118

118

to make the whole end operation false as well. 119

119

Okay, but let it set back to true. 120

120

And now, we can use this to improve our decision making, 121

121

whether Sarah should drive or not. 122

122

So with this third variable now, 123

123

we want Sarah to be able to drive 124

124

if she has a driver's license, if she has good vision 125

125

and if she is not tired, right? 126

126

So let's now translate that into a condition. 127

127

And I will just copy this one 128

128

and then comment all of it out using Command 129

129

or Control/ just like many times before 130

130

and now we will improve this one. 131

131

So this one, of course, is the same 132

132

that she needs to have a driver's license and good vision. 133

133

But now additionally, we want her to be not tired. 134

134

So right now she is tired, it's true 135

135

and that's, of course, not good for driving. 136

136

So we want the opposite of being tired. 137

137

And so therefore, we need to invert it. 138

138

So do you remember how that works? 139

139

All we need to do is to use the NOT operator. 140

140

So not is tired, all right? 141

141

So let's read this again, 142

142

Sarah is able to drive if she has a driver's license. 143

143

So if this one is true, if she has good vision, 144

144

so if this one is true and if she is not tired, 145

145

so if all of this is true here. 146

146

So only in this condition, Sarah is able to drive. 147

147

Now how is this part here true? 148

148

Well, it's true, when is tired is false, right? 149

149

So what do you think will happen 150

150

in this situation right now? 151

151

Well, let's test and then analyze. 152

152

So we get the result, someone else should drive. 153

153

So why is that? 154

154

Well, this one is true, 155

155

this one is true as we see up here, 156

156

and then is tired is also true. 157

157

However, not is tired is false. 158

158

So this part here is false. 159

159

And so true and true and false is of course, false. 160

160

And so therefore, we get the else block, 161

161

someone else should drive. 162

162

Now to fix this, 163

163

we need to change is tired to false, all right? 164

164

And so right now is tired is false 165

165

and therefore not is tired will become true. 166

166

And then we have true and true and true 167

167

and then in this situation, Sarah will be able to drive. 168

168

Yes, indeed, it works now. 169

169

So as you see, with these three Boolean operators, 170

170

we can model all kinds of companies decisions like this one. 171

171

Now, I know that this was probably a bit confusing, 172

172

but please don't worry too much, 173

173

because it's all very confusing for everyone 174

174

when they first learn how to program, okay? 175

175

Just take some time after this video 176

176

and analyze again exactly what happens here. 177

177

Maybe also together with the last video 178

178

to really make sure that you understand 179

179

what is going on here. 180

180

But of course, the best way to retain any knowledge 181

181

is by practicing and reinforcing it. 182

182

And so let's do that now in the next coding challenge.

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.