All language subtitles for 126 Control Statements_ Using If-Else Conditionals _ Logic.en_US

af Afrikaans
ak Akan
sq Albanian
am Amharic
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
fa Persian
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

Now, in the last lesson, we created what is the basic structure of a love calculator using randomisation

and Javascript.

Now, wouldn't it be nice if we could give the user a custom message based on what they got as their love

score?

Now in order to do this we need a way of checking what score they got and responding differently based

on that score.

And to do that we need to use conditionals. The way that conditional statements work is, you can use the

keyword if to evaluate a statement.

For example, in this case, if the track is clear. And, if that statement is true, then it will carry out

a particular sequence of code.

But if that statement is false,

so the track is not clear,

then you can have an ELSE keyword that tells the computer what it should do instead

in that case. And this, in programming, is known as control flow. We're essentially controlling the flow

of our code depending on the current conditions.

By the way I had a lot of fun building that toy train set in Keynote. In case anybody else is living

in a cramped London apartment and you don't have the space for a full toy set, and you're probably too

old to play with them anyways,

Keynote is your best bet. Now,

this is how we might express our little track scenario in code.

So we have the keyword if,

and then we have some parentheses.

And inside the parentheses are some conditions.

So if the track is equal to clear then we take the flow of the code into the curly braces straight after

and then we run the function goStraight. However, if that condition is not true, i.e. track does not

equal clear, then the code flows to the else statement,

and we run the function turnRight instead.

While this is an easy way of seeing how our code works, it doesn't look very good when we have lots and

lots of code inside the if and else statement,

so more commonly you'll see this code structured like this by Javascript programmers.

So we say if, we test the condition, and that's followed straightaway by the block of code that will

get carried out if that condition is true, and then we open up the else statement to specify what should

happen if that condition is not true. And essentially, through the testing of these conditions, we get

to control the flow of code,

and that's why they're called conditionals. So let's use what we learned to edit our code in the love calculator.

So we have a love score here and we know that we get a number between 1 to 100.

So that will be the condition that we will test.

So we will say if, which is the keyword here, and then we'll open up some parentheses to add our testing

condition.

So let's say that our condition was that loveScore is equal to 100.

And in order to test for equality we're using three equal signs.

And if that is true then this block of code will be executed.

But if it's not true, i.e. else, then this block of code will be executed instead.

So let's say that, if loveScore was equal to 100.

Well that's pretty crazy, right?

Then we should say something like, alert "Your love score is " this amount.

And then we should give them an interpretation.

Like, for example, "You love each other like Kanye loves Kanye.".

But otherwise we just give them the plain old normal message where we tell them their love score.

Now some might have realized that I would have to go through this many many times until I happened to

get a love score that is 100, which is quite unlikely.

I mean it's 1 percent likely, right?

So what if we simply wanted to test for a range, say for example if the love score was between 70 and

100, or if the love score was between 0 and 30?

Well, in order to do that, then we would have to use something like greater than.

So if love score was greater than 70 then we should get this alert,

otherwise we get this simple one instead.

So let's try this out and we get 58 on the first go.

There we go.

So we finally got above 70.

We've got 76 percent.

And we get told that we love each other like Kanye loves Kanye.

I used to love Kanye.

I thought I was Kanye. What if Kanye made a song about Kanye?

Man that would be so Kanye.

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