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
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
Persian
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
I hope you're excited
for your next coding challenge
so let's jump right in.
And this time we have a different coding challenge.
So, this time we have two gymnastics teams
called the Dolphins and the Koalas.
And they compete against each other three times,
then the team with the highest ever score
is the winner and wins a trophy.
So here are your tasks.
First, you should calculate the average score
for each of the teams using the test data below.
So, this test data right here, okay.
Then compare the teams' average scores
to determine the winner of the competition
and also print it to the console.
Now there might be a draw between the teams
which means that they have the same average score.
So, you need to test for that situation as well.
So this is the basic challenge
and I think this will be great to test the knowledge
that you gained over the last couple of videos.
Now if you want to take it to the next level
and make it a little more difficult,
you can try out the bonus one and bonus two.
So, let's take a look at this.
So, bonus one is to include the requirement
for a minimum score of 100.
So what this means is that the team only wins
if it has a higher score than the other team.
And, at the same time a score of at least 100 points.
And to help you solve this one,
I'm giving you the hint of using a logical operator
to test for the minimum score of 100 points.
Also, you will also probably need multiple else if blocks.
All right.
Now the second bonus here,
is that the minimum score also applies to a draw.
So a draw only happens when both teams have the same score
and both have a score greater or equal 100 points.
And otherwise no team at all wins the trophy, all right.
And then here you actually have the test data for bonus one
and for bonus two.
And you can of course play around with these scores
and change them to match all the different scenarios, okay.
So these are not static,
they're just some initial values that make sense
but from there feel free to change them.
So the first two are the easier ones
and for these you use this test data.
Then to make it a bit more difficult
you can do bonus two and bonus one
and for that you use these two test data sets, all right?
Now if one of the bonuses turns out to be too hard for you
then just don't do it.
It's perfectly fine, okay.
What matters is that you don't become frustrated.
The goal here is really just to test the stuff
that we did before
and absolutely not to get you frustrated
and thinking that coding might not be for you, okay.
And again, don't focus on writing efficient
or optimized code at this point,
all we want here is to learn programming
and to learn JavaScript.
So, just make it work and, yeah...
That's it for instructions about this challenge.
So, pause the video now and I see you in a second.
Now okay, hopefully you managed to complete
at least point one and point two
and so let's start by solving these two.
So, number one is calculating the average of both teams.
So let's create one variable for each.
So, score Dolphins
and so to calculate the average
we simply add up all the three scores
and then divide it by 3.
So we already did something similar before
so that's 96 plus 108 plus 89,
and then divided by three.
And we need these parentheses
so that these plus operations are executed first.
Because the grouping...
So the parentheses have a higher precedence.
Okay, score Koalas is 88 plus 91 plus 110
And again divided by 3
And now let's quickly log both to the console here.
Score Dolphins and score Koalas.
Okay, so they're pretty close
but the Dolphins have a little bit higher of an average.
And so that's what we're working on in point two
where we're going to compare the average of both teams.
So, we're gonna use an if statement or if else probably.
So score dolphins, if it's greater than score Koalas
then log to the console,
Dolphins win the trophy.
And we can get fancy here with some emoji.
Let's see if we got one.
Ah! That's the one I'm looking for.
But of course once more,
you don't need to worry about this part.
Let's just copy this for the next one.
So, else...
And actually we are going to use an else if
because of the draw.
But let's talk about that one later.
So, if the score of the Koalas
is greater than score Dolphins
then we're gonna print the opposite,
so that Koalas win the trophy.
And finally, else if score Dolphins is equal to score Koalas
then we can simply say that no one wins the trophy,
or actually both win the trophy.
Okay, so let's test that and indeed,
we get that Dolphins win the trophy
and that because as we know, this value is greater.
And so actually this first condition here
turns out to be true right away
and so this block of code here gets executed.
Now let's just quickly increase
the score of the Koalas here.
Let's say 100, just to see if the second part also works
And it did, now the Koalas win the trophy.
Okay, but let's put it back here
and here you could have actually done it in another way.
So you could have done score Dolphins
less than score Koalas.
So basically you write the same as here
but instead of the greater,
you will have used the less than.
So that's the exact same thing and both are equally valid.
Then here in the last part
actually, we wouldn't even have needed this part
so that the score of Dolphins is equal to score of Koalas,
because that's actually the only scenario that's left
given these previous two conditions.
So, basically if none of these here were true,
really the only thing possible
would be that they had the same score
and so simple else block would have been enough here.
But anyway, this works just fine too
and so, again what matters is that you made it work
even if you did some things differently.
For example,
you could have stored the conditions
in separate boolean variables
or you could have structured the if else statement
in some different way.
But if you got the same result that we just saw here,
then congratulations.
That's a great work.
Well done, really.
So, maybe you even made it to bonus number one and two
and so let me solve them here now, as well.
So, let's start by calculating the average.
So, this is gonna be bonus one.
And yeah, let's copy this one, too.
Let's copy this one.
Let's copy this one.
So we should have done it all in one go
so that we can now command out this first part.
So, for test number one,
this should be 97,
then the second one should be 112 and 101
And for the Koalas, we have 109, 95 and 123.
Let's just quickly test.
And so right now the Koalas win the trophy.
So for now everything works the same
but now we need to include this important condition here,
which is that with this rule,
a team only wins if it has a higher score
than the other team, which we already have.
And, at the same time a score of at least 100 points.
Okay.
Easy enough.
So in this case, the Dolphins win.
But now we also need to ensure
that the Dolphins have a score higher or equal 100.
So let's just say that.
So Dolphins need to have a higher score than Koalas
and score Dolphins needs to be greater or equal 100
and that's it.
That's all we need for this requirement.
And then the same thing here.
So this is the scenario where the Koalas win.
So for the Koalas to win
they need to have a higher score than the Dolphins
and at the same time,
they need to have at least 100 points.
So just like before, greater or equal 100.
And so once more, we used a logical operator here
to model this situation essentially.
Okay, and actually with this we implemented
this bonus number one.
So let's try that again
and right now of course it still works
because both have a score higher than 100
but let's change that now here
according to test data two, to 106.
So, 106...
and now they both win the trophy.
So let's actually decrease all these points
like by 20.
So let's make it 81 and 86,
so the average should still be the same now
Yeah, but they're both below 100 now.
And so this brings us to our bonus number two
that says that the minimum score
should also apply to a draw.
So a draw only happens when both teams have the same score
and both score greater or equal 100 points, okay.
And otherwise, no team wins the trophy.
So that's important too.
So let's translate that.
So to be a draw, the score needs to be the same
which we already have.
And the score of Dolphins
needs to be greater or equal 100
and the score of Koalas needs to be greater, equal 100, okay
And else...
Well, then we can say that no one wins the trophy.
And let's just add some sad emoji here, okay.
Let's try that
and now we get that no one wins the trophy, okay.
So that's because their scores are now below 100.
And so, we actually enter this last case here.
But if we go back to the averages that we had before
so 106 and 101, let's see.
Now both win the trophy
because they have the same amount of points
and they both have a number of points above 100.
And so that's exactly what we have here.
So, same points,
Dolphins have over, or at least 100 points
and Koalas have at least 100 points.
And so in this case, both win the trophy.
Finally, let's also test the scenario
in which both have below
but the Dolphins have a little bit more.
Let's put this one here at 80, and so,
now we see that the Dolphins have 96 points
and the Koalas have 84
but still no one wins the trophy.
And that's because the Dolphins have more than the Koalas
so this part of the requirement is true
but they do not have over 100
so this part here is false, okay
and so true, this first part here is true
and the second part is false.
True and false gives false
and so then all of these are skipped
because they are also obviously false
and so we go straight to this last block.
And so no one wins the trophy
which is exactly what we were expecting
as a result here, okay.
Now if you didn't manage to do this here,
again, don't worry because I know that this is
a little bit complicated already
and so in case you managed to successfully
complete this challenge, then a huge congratulations to you.
Well done.
But if for some reason,
you were not able to complete the challenge
then don't worry all too much about it.
You can always go back to the lectures
where we first learned about these topics
and you can of course, after this video
also review the code a little bit more carefully
to make sure 100% that you understand
especially this last example that we just worked on, okay.
But anyway, great job in completing this challenge
and now I see you in the next video.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.