Hey, everyone, in this video, I'm going to solve the exercises of list one.
So the first thing we need to do is creating this new J.S. Phyo and making the link in the HDMI will
file.
So let's go to Visual Studio Code.
Let's go to the J.S. folder and we can just click on this new file button.
So the name of the file is going to be E X one dot J.S..
Now, let's go back there and see the message that we need to print.
So we're gonna need to send this to the consul.
So let me write this statement here.
So console the log.
This is the message that we need to show if we refresh the page now, nothing is going to happen because
we do not include the link yet.
So let's go to this file, which is this one.
And then we know that the best place to place the link is at the bottom of the page right before closing
the body element.
So right here.
So let's open a script tag.
And the path is going to be J.S. slash yak's one dot Jesus.
Let's save this.
Let's see if this is working.
So we are seeing the message.
So now we know that the link is working and now we are safe to move on to the next questions.
Number two, create variables to store your first name, last name and year of birth.
So let's go to Visual Studio Code.
If you want, you can do something like this to organize your code.
So.
No one.
And now this is number two, so let's create three variables.
So far.
First name.
I'm just going to invent some data here, so, John.
John Doe.
So this is the last name.
Now another variable for the year of birth.
So you're off.
Let's say nineteen eighty.
And now we need to calculate the age.
So we are going to need a current year.
So I'm going to create another variable for the current year.
And now I'm just going to type it in.
So 20 is when I'm recording this video.
The best thing would be to make it dynamic.
So JavaScript has functions to get the actual current here.
So our code is never going to be obsolete, but it's too soon to talk about this.
Later in the course, I'm going to teach you how to use.
Date and time functions.
For now, let's just use a static value.
So twenty is going to work fine for now.
Now, let's calculate the age so we can use in the message.
So the age is going to be current ear.
Minus.
Year of birth.
Now let's create the message.
So vare message.
I always like to put it inside a variable first before sending to the console.
So we have everything organized like this.
So as you can see, we're doing stuff step by step.
So the message let's go back there to get the message.
So here it is.
Now, let's replace everything here.
So here I just closed this string.
And I started another one here and now in the middle of them, I'm going to concatenate something which
is going to be first name.
Plus, an empty string or an empty space.
Then I'm going to concatenate the last name.
And now the rest of the message.
Don't forget to include a space here.
Otherwise, the first name is going to be to close with this last word.
So like this, here we have a comma, so we don't need a space here.
And now the age.
So let's close the string here, let's open another one here.
And in the middle, we can just include the age.
But the problem is that the age is a number.
So we should always make sure that we are working with the same data types, even though this would
work.
It's not safe to do this.
So it's better to just apply a two string method.
Pretty cool.
Now, let's send this to that element.
Let's go back there and see.
So this is the idea of the element, student message.
So now we can just do document.
That get element by I.D..
This is the idea of the element.
So that inner H.T. Amelle.
It's going to be our message.
Let's save this.
Let's refresh the page and now we have.
Hi, my name is John Doe.
As you can see, I forgot the spaces for the age.
So let's go back there.
So a space here, space here.
Let's try again.
And now it's working.
Next up, get the two numbers below and calculate the average.
So let's see the I.D. of these elements.
So let's inspect this.
So I have a name one.
And here I have numb to.
So the first variable is going to be for number one.
Let's just copy this.
So we don't have to type everything again.
But this time, the I.D. of the element is number one.
Let me just check if it's.
Yeah.
It has an underscore.
So, number one.
Let's do the same thing for a number two.
So narm to.
He's going to be what's in that element.
Don't forget that when we do this, we are actually getting strings.
So we are going to have to convert it to no sense since these are integers.
We can just use the pass int.
Function so pass int.
And the same thing here.
So now we have numbers.
Now, let's calculate the average Savar.
Average.
It's going to be.
NARM one plus numb two inside parentheses, so this operation is done first.
Divided by two.
Now we need to send this result to this box.
Let's check the idea of this box.
So the idea is result.
Let's just copy this again.
This time, the I.D. is result.
And we want to send the average.
Let's save this.
Let's go back there.
Just one thing.
Let's remember that it is telling us to show the result of two decimal places.
Now that we have created the variable already, we can call it without the var keyword.
So we can just do average.
Equals.
Average Dott to.
Fixed.
And now we need to use two decimal places.
This should look good.
Going back there.
Refreshing the page.
So here it is.
Even though it's a round number, we are forcing it to show two decimal places.
If this was, let's say, the price for a product.
So it would make sense to show the decimal places even though it's zero.
So this one is done.
Now, number four, suppose telephone numbers with nine digits are valid, all orders are invalid.
Use JavaScript to test if the below numbers are valid.
So we can just copy them.
Let's take it to Visual Studio called.
So here it was actually number three.
I just forgot to change it.
Now it's number four.
And we have these three phone numbers.
We just have to validate them and send the result to the consul.
So since we are working with strings, we know that we can just get the length to see if it has four
characters or not.
So this is how we are going to validate these phone numbers if you want.
You can create a conditional I just showed you how you can use an if statement to show different messages.
So you could do like if phone one dot lenth.
Equals nine.
And then you show a personalized message.
You can do it like this or if you want.
You can just sprint true or fast to the console.
I left this up to you.
I just wanted you to know how to validate the numbers.
So it's up to you how you are going to show the result in the console.
I'm just going to print.
True or false?
So for the first number.
I'm just going to do console the log and then I'm just going to do the test.
So phone one dot lenth.
Equals nine.
So if this is valid, then I'm just going to show true in the console, then I'm going to do the same
things for.
Second phone number and third phone number.
So second and third, the problem with the third.
And this was a little challenge that I wanted to add.
This is a number.
So we cannot do the length.
We have numbers.
This is why we're going to have to do something like phone three equals phone three.
Got to.
String.
So now this is going to work.
Let's save this.
Let's refresh the page.
Go into the can so we can see that the first one is valid.
The second one is invalid.
And the third one is also valid.
All right.
Number five.
To the console, the result of the following operation.
This is pretty easy to do.
So number five.
We can just send to the consul.
The result of thirty two to the power off six.
So we have two ways of doing this.
I only talked about one, which is using the math object so we can do math dot Pough, which is a method
and then we can do thirty two to the power of six.
So we are passing two numbers here.
The base and the power.
Doing this, refreshing the page.
We have the results here.
There is another way of doing this.
If you want to do this exponential operation, you can just do 32.
And then two asterisks.
Then the power, as you can see.
You have the same result.
So next one, we have a few variable names to validate.
I'm just going to stop this video now because this is getting a bit too long.
So in the next video, I'm going to solve a number six.
Number seven and number eight.
I'll see you then.