Now that we covered some important basics
about variables, I want you to practice
what we learnt up to this point.
And I want you to take this 32, value you this number
and store it in a variable instead of using it here
in the place where we need it.
Instead, store it in a variable
at the beginning of our script,
and then use that variable down here.
Maybe also we'll use two alerts
that then work with that variable
to make adding that variable a bit more useful.
Now, one important hint,
which you will need for creating this variable,
this value 32 could be a age,
but that might matter for picking a proper variable name.
That's my challenge for you, add this new variable,
I'll give you a short pause, to pause the video
and try this on your own
thereafter, we'll do this together.
So, did you succeed?
Let's do this together.
We wanna create a second variable.
And I mentioned that you should add it somewhere
at the beginning of this script,
though I wanna emphasize that you can add the variables
anywhere in your script.
You can add them at the end,
in between and at the beginning.
Now at the end doesn't make sense here
since I wanna use it in my code.
So adding the variable thereafter would not work
since the code is executed from top to bottom.
Adding it in the middle or maybe a right before I plan
on using it would work.
But since my instruction for you
was to add it at the beginning of the script,
I wanna add it here or maybe after greeting text, up to you.
I will add it right at the top.
Now we did learn that we can now add a new variable
with the let keyword.
That's what we used before as well.
And then we need to pick a name.
That name as you learnt is up to you,
but has to follow certain rules and conventions
and which name we choose
depends on what that value represents.
And here, I'm assuming it represents my age.
So I will name the variable age.
Now that's my name and the interesting thing about this name
of course is that, unlike greeting text,
this has no capital characters inside of it
because that's not a must do.
It's only a must to do if your variable name
actually consists of multiple words,
sometimes you might need that
to properly describe the value.
In the case of age, the word age is enough to describe that.
Guess what, a number that represents an age
is stored in there.
We could of course also choose user age instead,
and then write it like this, but that's totally optional.
It would also be fine though,
but here I'll go for age and then store 32 as a value.
And I will also add that semi-colon,
since that is the style I will use in this course,
and that is a style you will see a lot out there in general.
And now that this variable was created, we can use it.
We can use it here for the alert
and output age by referencing it.
So by basically telling JavaScript
and therefore the browser, "Hey, please show an alert"
and the content of the alert
should be the value stored in age.
That's what we're telling JavaScript here.
And of course we can also output multiple alerts
for this age like this.
And if I save that, if I reload this page, I get high IMAX,
twice, and then that changed text.
And then there after, I get my age, 32 being output twice.
And of course we could now also change
that variable somewhere
and assign a new value again with the equal sign,
as we're doing it with creating text.
And that's something you can do,
but not something you need to do here.
And that's now another variable introduced.