1
00:00:09,680 --> 00:00:14,600
Hey, everyone, in this video, I'm going to solve the exercises of list one.

2
00:00:14,990 --> 00:00:22,620
So the first thing we need to do is creating this new J.S. Phyo and making the link in the HDMI will

3
00:00:22,670 --> 00:00:23,150
file.

4
00:00:23,510 --> 00:00:25,490
So let's go to Visual Studio Code.

5
00:00:25,970 --> 00:00:32,300
Let's go to the J.S. folder and we can just click on this new file button.

6
00:00:33,320 --> 00:00:37,820
So the name of the file is going to be E X one dot J.S..

7
00:00:39,850 --> 00:00:43,960
Now, let's go back there and see the message that we need to print.

8
00:00:44,200 --> 00:00:47,080
So we're gonna need to send this to the consul.

9
00:00:48,440 --> 00:00:51,140
So let me write this statement here.

10
00:00:51,170 --> 00:00:53,000
So console the log.

11
00:00:55,740 --> 00:01:02,100
This is the message that we need to show if we refresh the page now, nothing is going to happen because

12
00:01:02,100 --> 00:01:04,290
we do not include the link yet.

13
00:01:04,650 --> 00:01:07,650
So let's go to this file, which is this one.

14
00:01:09,090 --> 00:01:16,530
And then we know that the best place to place the link is at the bottom of the page right before closing

15
00:01:16,530 --> 00:01:17,660
the body element.

16
00:01:17,790 --> 00:01:18,720
So right here.

17
00:01:19,190 --> 00:01:21,990
So let's open a script tag.

18
00:01:24,280 --> 00:01:30,370
And the path is going to be J.S. slash yak's one dot Jesus.

19
00:01:31,390 --> 00:01:32,500
Let's save this.

20
00:01:32,710 --> 00:01:34,270
Let's see if this is working.

21
00:01:34,510 --> 00:01:36,220
So we are seeing the message.

22
00:01:36,520 --> 00:01:42,840
So now we know that the link is working and now we are safe to move on to the next questions.

23
00:01:44,240 --> 00:01:50,300
Number two, create variables to store your first name, last name and year of birth.

24
00:01:50,840 --> 00:01:53,540
So let's go to Visual Studio Code.

25
00:01:54,770 --> 00:01:59,100
If you want, you can do something like this to organize your code.

26
00:01:59,420 --> 00:02:00,170
So.

27
00:02:02,190 --> 00:02:03,060
No one.

28
00:02:06,520 --> 00:02:10,290
And now this is number two, so let's create three variables.

29
00:02:10,320 --> 00:02:11,220
So far.

30
00:02:13,230 --> 00:02:14,190
First name.

31
00:02:17,930 --> 00:02:20,870
I'm just going to invent some data here, so, John.

32
00:02:28,700 --> 00:02:29,570
John Doe.

33
00:02:31,800 --> 00:02:33,510
So this is the last name.

34
00:02:33,870 --> 00:02:36,450
Now another variable for the year of birth.

35
00:02:36,840 --> 00:02:39,240
So you're off.

36
00:02:42,650 --> 00:02:44,960
Let's say nineteen eighty.

37
00:02:47,240 --> 00:02:49,160
And now we need to calculate the age.

38
00:02:49,190 --> 00:02:51,340
So we are going to need a current year.

39
00:02:51,650 --> 00:02:55,100
So I'm going to create another variable for the current year.

40
00:02:57,240 --> 00:02:59,170
And now I'm just going to type it in.

41
00:02:59,210 --> 00:03:02,830
So 20 is when I'm recording this video.

42
00:03:03,730 --> 00:03:06,610
The best thing would be to make it dynamic.

43
00:03:06,640 --> 00:03:11,380
So JavaScript has functions to get the actual current here.

44
00:03:11,620 --> 00:03:17,020
So our code is never going to be obsolete, but it's too soon to talk about this.

45
00:03:17,320 --> 00:03:20,000
Later in the course, I'm going to teach you how to use.

46
00:03:20,020 --> 00:03:21,670
Date and time functions.

47
00:03:22,120 --> 00:03:25,570
For now, let's just use a static value.

48
00:03:25,570 --> 00:03:29,200
So twenty is going to work fine for now.

49
00:03:30,980 --> 00:03:34,560
Now, let's calculate the age so we can use in the message.

50
00:03:34,760 --> 00:03:37,370
So the age is going to be current ear.

51
00:03:39,920 --> 00:03:40,790
Minus.

52
00:03:43,320 --> 00:03:44,280
Year of birth.

53
00:03:46,340 --> 00:03:48,170
Now let's create the message.

54
00:03:48,530 --> 00:03:51,170
So vare message.

55
00:03:52,530 --> 00:03:57,780
I always like to put it inside a variable first before sending to the console.

56
00:03:58,050 --> 00:04:00,690
So we have everything organized like this.

57
00:04:01,020 --> 00:04:04,200
So as you can see, we're doing stuff step by step.

58
00:04:04,530 --> 00:04:07,980
So the message let's go back there to get the message.

59
00:04:09,290 --> 00:04:10,340
So here it is.

60
00:04:16,290 --> 00:04:18,960
Now, let's replace everything here.

61
00:04:28,950 --> 00:04:31,730
So here I just closed this string.

62
00:04:32,930 --> 00:04:39,410
And I started another one here and now in the middle of them, I'm going to concatenate something which

63
00:04:39,410 --> 00:04:42,200
is going to be first name.

64
00:04:43,880 --> 00:04:48,350
Plus, an empty string or an empty space.

65
00:04:48,740 --> 00:04:52,940
Then I'm going to concatenate the last name.

66
00:04:53,420 --> 00:04:55,580
And now the rest of the message.

67
00:04:56,180 --> 00:04:58,310
Don't forget to include a space here.

68
00:04:58,700 --> 00:05:04,580
Otherwise, the first name is going to be to close with this last word.

69
00:05:05,330 --> 00:05:09,620
So like this, here we have a comma, so we don't need a space here.

70
00:05:10,010 --> 00:05:11,360
And now the age.

71
00:05:14,160 --> 00:05:17,660
So let's close the string here, let's open another one here.

72
00:05:24,130 --> 00:05:28,120
And in the middle, we can just include the age.

73
00:05:28,150 --> 00:05:31,090
But the problem is that the age is a number.

74
00:05:32,610 --> 00:05:39,450
So we should always make sure that we are working with the same data types, even though this would

75
00:05:39,450 --> 00:05:39,990
work.

76
00:05:40,140 --> 00:05:41,730
It's not safe to do this.

77
00:05:42,060 --> 00:05:48,420
So it's better to just apply a two string method.

78
00:05:49,810 --> 00:05:50,560
Pretty cool.

79
00:05:50,780 --> 00:05:54,070
Now, let's send this to that element.

80
00:05:54,160 --> 00:05:56,080
Let's go back there and see.

81
00:05:56,470 --> 00:06:00,850
So this is the idea of the element, student message.

82
00:06:02,130 --> 00:06:04,650
So now we can just do document.

83
00:06:07,960 --> 00:06:10,540
That get element by I.D..

84
00:06:11,020 --> 00:06:13,000
This is the idea of the element.

85
00:06:13,390 --> 00:06:16,200
So that inner H.T. Amelle.

86
00:06:17,820 --> 00:06:20,670
It's going to be our message.

87
00:06:21,690 --> 00:06:22,650
Let's save this.

88
00:06:24,250 --> 00:06:27,730
Let's refresh the page and now we have.

89
00:06:27,970 --> 00:06:29,620
Hi, my name is John Doe.

90
00:06:30,720 --> 00:06:34,620
As you can see, I forgot the spaces for the age.

91
00:06:34,710 --> 00:06:36,150
So let's go back there.

92
00:06:36,990 --> 00:06:39,630
So a space here, space here.

93
00:06:42,910 --> 00:06:43,990
Let's try again.

94
00:06:44,140 --> 00:06:46,480
And now it's working.

95
00:06:47,850 --> 00:06:53,250
Next up, get the two numbers below and calculate the average.

96
00:06:53,280 --> 00:06:56,050
So let's see the I.D. of these elements.

97
00:06:56,160 --> 00:06:57,690
So let's inspect this.

98
00:06:57,900 --> 00:06:59,430
So I have a name one.

99
00:07:02,500 --> 00:07:04,900
And here I have numb to.

100
00:07:15,380 --> 00:07:18,590
So the first variable is going to be for number one.

101
00:07:18,620 --> 00:07:20,840
Let's just copy this.

102
00:07:20,890 --> 00:07:23,240
So we don't have to type everything again.

103
00:07:25,250 --> 00:07:29,180
But this time, the I.D. of the element is number one.

104
00:07:30,150 --> 00:07:31,860
Let me just check if it's.

105
00:07:31,920 --> 00:07:32,140
Yeah.

106
00:07:32,190 --> 00:07:33,510
It has an underscore.

107
00:07:33,990 --> 00:07:36,210
So, number one.

108
00:07:42,290 --> 00:07:44,480
Let's do the same thing for a number two.

109
00:07:44,510 --> 00:07:45,650
So narm to.

110
00:07:46,890 --> 00:07:49,380
He's going to be what's in that element.

111
00:07:49,830 --> 00:07:53,840
Don't forget that when we do this, we are actually getting strings.

112
00:07:54,360 --> 00:08:01,080
So we are going to have to convert it to no sense since these are integers.

113
00:08:01,110 --> 00:08:04,620
We can just use the pass int.

114
00:08:06,060 --> 00:08:09,750
Function so pass int.

115
00:08:11,410 --> 00:08:13,120
And the same thing here.

116
00:08:17,270 --> 00:08:18,970
So now we have numbers.

117
00:08:20,130 --> 00:08:22,520
Now, let's calculate the average Savar.

118
00:08:24,060 --> 00:08:24,840
Average.

119
00:08:25,920 --> 00:08:27,030
It's going to be.

120
00:08:28,160 --> 00:08:36,910
NARM one plus numb two inside parentheses, so this operation is done first.

121
00:08:38,420 --> 00:08:39,800
Divided by two.

122
00:08:41,600 --> 00:08:46,430
Now we need to send this result to this box.

123
00:08:46,880 --> 00:08:49,040
Let's check the idea of this box.

124
00:08:49,460 --> 00:08:51,770
So the idea is result.

125
00:08:53,500 --> 00:08:55,360
Let's just copy this again.

126
00:08:56,590 --> 00:08:59,070
This time, the I.D. is result.

127
00:09:01,170 --> 00:09:04,050
And we want to send the average.

128
00:09:06,290 --> 00:09:07,280
Let's save this.

129
00:09:07,310 --> 00:09:08,650
Let's go back there.

130
00:09:09,530 --> 00:09:10,550
Just one thing.

131
00:09:10,580 --> 00:09:17,330
Let's remember that it is telling us to show the result of two decimal places.

132
00:09:17,570 --> 00:09:23,030
Now that we have created the variable already, we can call it without the var keyword.

133
00:09:23,180 --> 00:09:24,950
So we can just do average.

134
00:09:26,360 --> 00:09:27,140
Equals.

135
00:09:29,280 --> 00:09:31,620
Average Dott to.

136
00:09:32,570 --> 00:09:33,260
Fixed.

137
00:09:41,590 --> 00:09:45,120
And now we need to use two decimal places.

138
00:09:48,580 --> 00:09:49,780
This should look good.

139
00:09:50,140 --> 00:09:51,150
Going back there.

140
00:09:51,190 --> 00:09:52,750
Refreshing the page.

141
00:09:53,530 --> 00:09:54,520
So here it is.

142
00:09:55,530 --> 00:10:02,340
Even though it's a round number, we are forcing it to show two decimal places.

143
00:10:02,580 --> 00:10:06,060
If this was, let's say, the price for a product.

144
00:10:06,420 --> 00:10:11,370
So it would make sense to show the decimal places even though it's zero.

145
00:10:12,060 --> 00:10:13,290
So this one is done.

146
00:10:13,530 --> 00:10:20,880
Now, number four, suppose telephone numbers with nine digits are valid, all orders are invalid.

147
00:10:21,330 --> 00:10:24,810
Use JavaScript to test if the below numbers are valid.

148
00:10:25,140 --> 00:10:26,800
So we can just copy them.

149
00:10:28,810 --> 00:10:31,090
Let's take it to Visual Studio called.

150
00:10:33,250 --> 00:10:35,710
So here it was actually number three.

151
00:10:36,730 --> 00:10:38,300
I just forgot to change it.

152
00:10:38,330 --> 00:10:39,980
Now it's number four.

153
00:10:44,500 --> 00:10:47,410
And we have these three phone numbers.

154
00:10:47,440 --> 00:10:51,670
We just have to validate them and send the result to the consul.

155
00:10:53,060 --> 00:11:00,680
So since we are working with strings, we know that we can just get the length to see if it has four

156
00:11:01,370 --> 00:11:02,840
characters or not.

157
00:11:02,990 --> 00:11:07,340
So this is how we are going to validate these phone numbers if you want.

158
00:11:07,370 --> 00:11:15,530
You can create a conditional I just showed you how you can use an if statement to show different messages.

159
00:11:15,830 --> 00:11:20,720
So you could do like if phone one dot lenth.

160
00:11:21,910 --> 00:11:23,560
Equals nine.

161
00:11:23,770 --> 00:11:26,380
And then you show a personalized message.

162
00:11:26,620 --> 00:11:28,840
You can do it like this or if you want.

163
00:11:29,110 --> 00:11:32,110
You can just sprint true or fast to the console.

164
00:11:32,680 --> 00:11:34,870
I left this up to you.

165
00:11:35,140 --> 00:11:38,410
I just wanted you to know how to validate the numbers.

166
00:11:38,420 --> 00:11:43,450
So it's up to you how you are going to show the result in the console.

167
00:11:44,480 --> 00:11:45,680
I'm just going to print.

168
00:11:45,710 --> 00:11:47,120
True or false?

169
00:11:47,630 --> 00:11:49,070
So for the first number.

170
00:11:50,540 --> 00:11:55,430
I'm just going to do console the log and then I'm just going to do the test.

171
00:11:55,550 --> 00:11:59,810
So phone one dot lenth.

172
00:12:01,150 --> 00:12:02,650
Equals nine.

173
00:12:03,400 --> 00:12:09,790
So if this is valid, then I'm just going to show true in the console, then I'm going to do the same

174
00:12:09,790 --> 00:12:10,900
things for.

175
00:12:12,370 --> 00:12:15,000
Second phone number and third phone number.

176
00:12:16,050 --> 00:12:19,740
So second and third, the problem with the third.

177
00:12:20,070 --> 00:12:23,250
And this was a little challenge that I wanted to add.

178
00:12:23,790 --> 00:12:24,830
This is a number.

179
00:12:24,840 --> 00:12:26,580
So we cannot do the length.

180
00:12:26,820 --> 00:12:27,810
We have numbers.

181
00:12:28,900 --> 00:12:36,190
This is why we're going to have to do something like phone three equals phone three.

182
00:12:38,500 --> 00:12:39,580
Got to.

183
00:12:41,440 --> 00:12:42,040
String.

184
00:12:44,130 --> 00:12:46,020
So now this is going to work.

185
00:12:46,290 --> 00:12:47,340
Let's save this.

186
00:12:47,520 --> 00:12:49,080
Let's refresh the page.

187
00:12:50,250 --> 00:12:53,670
Go into the can so we can see that the first one is valid.

188
00:12:54,510 --> 00:12:56,250
The second one is invalid.

189
00:12:56,490 --> 00:12:59,000
And the third one is also valid.

190
00:13:01,070 --> 00:13:01,400
All right.

191
00:13:01,430 --> 00:13:02,300
Number five.

192
00:13:02,740 --> 00:13:06,380
To the console, the result of the following operation.

193
00:13:06,650 --> 00:13:08,870
This is pretty easy to do.

194
00:13:10,710 --> 00:13:11,850
So number five.

195
00:13:16,470 --> 00:13:18,300
We can just send to the consul.

196
00:13:20,860 --> 00:13:24,190
The result of thirty two to the power off six.

197
00:13:24,310 --> 00:13:26,500
So we have two ways of doing this.

198
00:13:26,770 --> 00:13:36,760
I only talked about one, which is using the math object so we can do math dot Pough, which is a method

199
00:13:37,060 --> 00:13:41,590
and then we can do thirty two to the power of six.

200
00:13:41,770 --> 00:13:44,080
So we are passing two numbers here.

201
00:13:44,590 --> 00:13:46,900
The base and the power.

202
00:13:47,960 --> 00:13:50,540
Doing this, refreshing the page.

203
00:13:51,920 --> 00:13:53,300
We have the results here.

204
00:13:53,570 --> 00:13:55,370
There is another way of doing this.

205
00:13:55,730 --> 00:14:00,700
If you want to do this exponential operation, you can just do 32.

206
00:14:01,040 --> 00:14:02,960
And then two asterisks.

207
00:14:04,110 --> 00:14:06,210
Then the power, as you can see.

208
00:14:06,360 --> 00:14:08,280
You have the same result.

209
00:14:09,660 --> 00:14:14,220
So next one, we have a few variable names to validate.

210
00:14:14,670 --> 00:14:18,930
I'm just going to stop this video now because this is getting a bit too long.

211
00:14:19,200 --> 00:14:22,730
So in the next video, I'm going to solve a number six.

212
00:14:23,040 --> 00:14:24,990
Number seven and number eight.

213
00:14:25,290 --> 00:14:26,040
I'll see you then.
