All language subtitles for 106 Javascript Variables Exercise Solution.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

All right so hopefully you gave that challenge a good go and you managed to get the correct solution.

Abiding by all of the rules now the rules are there because we want to test your understanding of variables

and this particular exercise is something that you often see encoding interviews where they're trying

to test a candidate's thinking process how they go about reasoning using code.

So let's go through the solution together and see if you got it right now as I mentioned previously

were not allowed to change any of the existing code.

So the solution can't just be us changing this from three to eight and that from eight to three.

This is wrong.

The second rule is we're not allowed to type any numbers so we can't just simply say well net a now

equals eight and b now equals three.

This is also wrong because it breaks the second rule.

Now the last rule is we're not allowed to re declare the variables A and B.

So finally we can't say a equals eight and b variable B equals three.

In this case we've actually just created two new variables.

And you can see we're getting a little warning on the side and it says that a is ready to find b is

ready defined up here.

So we can't re declare them.

So given all of those constraints how do we arrive at the answer.

Well as I showed you earlier on it's really useful to think about it in terms of real objects to understand

the logic.

Now we said that we've got two variables right.

A and B and we can imagine them as two buckets bucket and Bucket B.

Now a contained son and B contains water.

How would we switch the contents of the buckets around so that a hold water and b hold sand.

Well if this was a real life situation then the simplest way is probably just getting hold of another

bucket right.

And this is exactly the same solution that we're going to implement using code as well.

So always remember that coding is not the hard part.

Remembering what the semicolons are equal sign.

This is all very easy.

The difficult part is getting the logic in the first place.

So let's create this variable C and let's get it to hold some of the content that's currently inside

a.

And now that a is freed up we can use a to hold what's inside B.

And finally we can get B to hold what is inside C which is what was previously inside a.

So now let's go ahead and test our code.

So I'm just going to copy these three lines and I'm going to paste it inside here and when I hit run

you can see that now a is a and b is three and just these three lines of code allowed us to do the bucket

switch and if we click check solution then everything should pass and we should be allowed to continue.

So how did you get on with this challenge if you got really stuck and you don't understand why the solution

is the way it is then I urge you to just think about the buckets.

Think about how you would do it in real life.

What is the logic of switching the contents between A and B around when you have a Bucket C and then

the code is going to become a lot more easily understood.

So if you need a moment pause a video and have a think about it and then once you're ready head over

to the next lesson.

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