(musical sting)
- [Instructor] Let's go through the solution
of the challenge.
Keep in mind your code could be anything you wanted
as long as you're able to validate the local variables
aren't available globally.
So let's take a look at mine.
So what I did here is first define a global variable
called number of platoon to 45,
then created a function called platoon,
and inside of that function I defined two local variables.
So one is the warriors per platoon at 60,
and then a total warriors,
which is the number of platoon
multiplied by warriors per platoon,
and then returned our army is total warriors strong.
So this should give us the 45 multiplied by 60 here
and return it inside of this template strings here,
and then we console log.
So if we save this
and we go to our browser,
our army is 2700 strong.
Also I've put some notes in here.
So if we wanna test that warriors per platoon
are indeed local
and not available globally,
we can uncomment this line 17 here
and take a look at if these variables are available.
And I've got a reference error.
And again, this is the best way to validate
that these variables are local, not global.
You can actually try to console log them
scoped globally or locally
and see if they're available.
So let's comment that again.
If we remove the comment for number of platoon and save it,
then because this one is globally available,
we should have it in here and says 45.
So as you can see,
understanding and working with global and local scope
is not that hard.
Once you grasp the nuances of each,
then you should be good to go.
Let's move on.