Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
Here is another
exercise. I want you to implement this function.
Function isLandscape, it takes two parameters,
width, and height of an image, and returns true
if the image is landscape, which means width is greater than
height, otherwise it returns false. Now you may think this
is similar to the exercise in the last lecture, in fact it is, but I want you to
do this exercise because I'm going to give you a simple and affective tip to
write better code. So pause the video, do the exercise, and then come back
and continue watching.
Alright, so similar to the last lecture, we can start
with a simple if and else. So if width is greater than
height, you want to return true, otherwise we want to return
false. But I told you that in this case we
can use the conditional operator, so,
we add the condition if width is greater than height,
we can return true, otherwise we'll return false.
And here's our return statement, right? So here's the implementation
of this function, however code like this looks very
amateurish. You don't want to return true or false
explicitly. This is very ugly. Why? Well, let me show you.
We can completely delete this part here
and simply return the value
of this expression. So if width is greater than
height, this expression will be evaluated to true. So,
you will simply return true. Otherwise, if width
is less than height, this expression will evaluate to false, sun will
return false. So there is really no need to explicitly return
true and false here, that's a pour way of writing code.
So, now we have this function, let's test
it. We can do a console.log, simply call this
function here isLandscape, I'm going to pass these dimensions
800 by 600. So we expect true on the
console. Save the changes, here's true, beautiful,
now let's change the width to let's say 300. Now we have
a vertical image. Save. So we get false.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.