1
00:00:09,220 --> 00:00:09,850
Hey, everyone.

2
00:00:09,940 --> 00:00:10,810
Welcome back.

3
00:00:11,020 --> 00:00:17,440
Continuing with the data types, we're now going to talk more about numbers before we get started.

4
00:00:17,470 --> 00:00:19,930
I just want to say something quickly.

5
00:00:20,290 --> 00:00:26,320
I'm just using the console to write the examples just so it's faster, just so I don't have to go back

6
00:00:26,320 --> 00:00:29,470
and forth to Visual Studio Code and then back here.

7
00:00:29,800 --> 00:00:34,450
But I encourage you to write all the examples inside the JSC file.

8
00:00:34,660 --> 00:00:36,560
So you have everything there.

9
00:00:36,820 --> 00:00:43,150
Of course, any time you want, you can come back here to the written material and check all the examples

10
00:00:43,150 --> 00:00:43,470
again.

11
00:00:43,510 --> 00:00:45,670
This is why I made this material.

12
00:00:46,270 --> 00:00:48,430
So having said that, let's move on.

13
00:00:48,640 --> 00:00:52,330
We know that we can assign numbers to variables.

14
00:00:52,780 --> 00:00:57,460
All we need to do is use only numbers and don't use quotation marks.

15
00:00:57,910 --> 00:01:03,440
So if we include quotation marks, JavaScript is going to treat this as a string.

16
00:01:03,670 --> 00:01:08,560
So like this, JavaScript knows we are working with a number.

17
00:01:08,770 --> 00:01:10,300
So we have integers.

18
00:01:10,510 --> 00:01:14,350
And we also have numbers with decimal places like this.

19
00:01:14,620 --> 00:01:16,360
We should always use DOT.

20
00:01:16,540 --> 00:01:17,820
So never use comma.

21
00:01:17,920 --> 00:01:21,730
And we also cannot use thousand separators.

22
00:01:21,940 --> 00:01:24,250
So if I have a price variable.

23
00:01:24,250 --> 00:01:28,900
So var price, let's say the price is more than a thousand.

24
00:01:29,170 --> 00:01:31,180
I can't do it like this.

25
00:01:31,420 --> 00:01:33,280
This is going to confuse JavaScript.

26
00:01:33,520 --> 00:01:35,470
And this is going to return an error.

27
00:01:36,010 --> 00:01:37,870
We never use thousand separator.

28
00:01:37,870 --> 00:01:39,040
So this is a thousand.

29
00:01:39,060 --> 00:01:40,930
This is ten thousand.

30
00:01:41,380 --> 00:01:43,300
This is how we write numbers.

31
00:01:43,360 --> 00:01:47,470
And if you have decimal places you should use DOT.

32
00:01:47,920 --> 00:01:50,860
So this is the right way of writing a number.

33
00:01:51,430 --> 00:01:58,300
We also have big numbers in JavaScript so we can represent them with this exponential notation.

34
00:01:58,330 --> 00:02:00,790
So we don't have a very, very long number.

35
00:02:01,420 --> 00:02:05,320
This number here means two times 10.

36
00:02:05,380 --> 00:02:07,620
By the power of 45.

37
00:02:07,930 --> 00:02:11,890
So now let's check some calculations that we can do with numbers.

38
00:02:12,160 --> 00:02:17,560
So, of course, we have the basic math operations when dealing with programs.

39
00:02:17,570 --> 00:02:20,650
We're going to do calculations all the time.

40
00:02:21,040 --> 00:02:24,790
So we need at least the basic math calculations.

41
00:02:25,150 --> 00:02:27,910
So I can have a variable.

42
00:02:29,720 --> 00:02:31,130
Called Numb one.

43
00:02:37,160 --> 00:02:40,970
Actually, I just added an empty space here.

44
00:02:41,180 --> 00:02:43,740
So now it's right, so numb.

45
00:02:43,850 --> 00:02:44,450
One.

46
00:02:45,760 --> 00:02:48,730
I'm also going to create another variable num, too.

47
00:02:49,620 --> 00:02:53,230
And now we can make any kind of calculations we want.

48
00:02:53,620 --> 00:02:57,250
So some is just going to be number one plus.

49
00:02:58,300 --> 00:03:02,620
Numb, too, as you can see, we have the calculation done here.

50
00:03:02,740 --> 00:03:04,510
We can also do subtraction.

51
00:03:04,540 --> 00:03:06,750
We have a dash division.

52
00:03:06,910 --> 00:03:12,070
We have a forward slash and multiplication with an asterisk.

53
00:03:12,490 --> 00:03:15,600
Just one thing that you might be asking yourself.

54
00:03:16,000 --> 00:03:20,380
Why was I using console dot log in the code?

55
00:03:20,430 --> 00:03:22,360
And now I'm not doing this anymore.

56
00:03:22,390 --> 00:03:25,010
I'm just typing in the operations directly.

57
00:03:25,420 --> 00:03:29,800
If you're in the console here, you can just type it directly like this.

58
00:03:30,040 --> 00:03:33,010
But this is not going to work in the JavaScript file.

59
00:03:33,400 --> 00:03:34,780
In the JavaScript file.

60
00:03:35,050 --> 00:03:40,330
If you want to send anything to the console, you need to write, console, dot log.

61
00:03:40,540 --> 00:03:45,370
So moving on, we can also use parentheses to form expressions.

62
00:03:45,700 --> 00:03:51,610
So if we want the average of these two numbers, you should just write it like this.

63
00:03:51,880 --> 00:03:54,820
So num one plus.

64
00:03:57,010 --> 00:03:59,350
Numb, too, divided by two.

65
00:04:00,130 --> 00:04:07,270
This is not going to be correct because following the hierarchy of math operations, it is going to

66
00:04:07,270 --> 00:04:11,340
do the division first and then it's going to do the some.

67
00:04:11,560 --> 00:04:17,560
So in order to sum the numbers first, we just enclose them inside parentheses like this.

68
00:04:17,860 --> 00:04:19,810
And then we do the division.

69
00:04:19,960 --> 00:04:22,450
So now we have the correct average.

70
00:04:22,660 --> 00:04:24,790
Let me clear this real quick.

71
00:04:27,030 --> 00:04:33,730
And now let's talk about the math object, if we want to go further with calculations, maybe we want

72
00:04:33,730 --> 00:04:37,090
more than just the basic math operations.

73
00:04:37,510 --> 00:04:40,510
We have a built in object in JavaScript.

74
00:04:40,570 --> 00:04:41,710
It is called math.

75
00:04:42,070 --> 00:04:51,190
We have a capital M so we can use it to make some more complex stuff like two to the power of four.

76
00:04:51,220 --> 00:04:52,690
So how can we do this?

77
00:04:53,020 --> 00:04:59,860
We can just type math and then any method of the math object can be access.

78
00:04:59,890 --> 00:05:02,260
We have a dot when you do this.

79
00:05:02,290 --> 00:05:03,570
You have all the lists.

80
00:05:03,610 --> 00:05:08,860
So the console brings all the list of methods that we can use with the math object.

81
00:05:09,400 --> 00:05:11,170
So if we type Powell.

82
00:05:12,750 --> 00:05:21,740
So now two to the power of four is just two karma, four to now we have the result, which is 16.

83
00:05:22,170 --> 00:05:27,480
We can also round numbers so we can use the round method.

84
00:05:28,380 --> 00:05:34,020
And this is going to just round to the nearest integer so I can do math.

85
00:05:37,100 --> 00:05:38,430
That round.

86
00:05:39,140 --> 00:05:44,540
And then if I'm trying to round two point seven, it is going to round two three.

87
00:05:45,110 --> 00:05:49,130
If I'm trying to round two point three, it is going to round two to.

88
00:05:50,250 --> 00:05:56,730
We can also round two, the current integer, so math dot floor.

89
00:05:58,360 --> 00:06:00,210
It doesn't matter if I have nine here.

90
00:06:00,250 --> 00:06:07,540
It is always going to round to the low integer and the opposite would be the CEO.

91
00:06:09,480 --> 00:06:10,080
Method.

92
00:06:10,380 --> 00:06:14,600
So this time it is going to round to the bigger integer.

93
00:06:14,650 --> 00:06:18,910
So even if I have to point to, it's still going to round two, three.

94
00:06:19,020 --> 00:06:21,480
Sometimes it's useful to do this.

95
00:06:21,660 --> 00:06:23,620
Now we also have the square root.

96
00:06:23,970 --> 00:06:28,540
And another very interesting thing we have with the math object.

97
00:06:28,680 --> 00:06:30,840
We programmers use this a lot.

98
00:06:30,870 --> 00:06:32,580
Is the random method.

99
00:06:32,820 --> 00:06:38,170
So if you do it like this, we always need parentheses for methods.

100
00:06:38,220 --> 00:06:43,170
We're going to talk more about this even if we don't pass anything inside.

101
00:06:43,530 --> 00:06:46,590
We should always use parentheses to run methods.

102
00:06:46,920 --> 00:06:49,050
So now we are calling the random method.

103
00:06:49,710 --> 00:06:56,700
And what it does is generating a completely random number between zero and one.

104
00:06:57,420 --> 00:07:00,150
So if I do this one time, it comes one number.

105
00:07:00,360 --> 00:07:01,890
If I do this another time.

106
00:07:02,220 --> 00:07:04,200
Now it's a different number.

107
00:07:04,440 --> 00:07:09,030
Every time we do it, it's going to be a completely different number.

108
00:07:09,150 --> 00:07:14,350
So now how can we have a random number between zero and 100?

109
00:07:14,550 --> 00:07:15,290
For example.

110
00:07:15,540 --> 00:07:16,560
Wow, it's easy.

111
00:07:16,800 --> 00:07:17,970
We can just do math.

112
00:07:18,030 --> 00:07:19,140
Dot random.

113
00:07:20,230 --> 00:07:23,020
Then we multiplied by 100.

114
00:07:24,080 --> 00:07:27,620
So the smallest one, which is zero, is going to be zero.

115
00:07:27,890 --> 00:07:33,030
And the biggest one, which would be zero point ninety nine, is going to be close to 100.

116
00:07:33,380 --> 00:07:37,680
So this way we have a random number from zero to 100.

117
00:07:37,970 --> 00:07:42,830
And now if we want to around it, we can just use the math that round.

118
00:07:47,080 --> 00:07:54,180
And now every time we run this, we are going to have a random number from zero to 100.

119
00:07:54,400 --> 00:07:57,920
Pretty cool right now besides the math object.

120
00:07:58,510 --> 00:08:04,270
We also have some methods that can be used with the no data type.

121
00:08:04,690 --> 00:08:08,500
So one example is the two fixed method.

122
00:08:08,680 --> 00:08:09,880
So wi fi, have a number.

123
00:08:09,910 --> 00:08:12,310
Let me just clear this real quick.

124
00:08:14,070 --> 00:08:16,470
I'm going to create a variable called my.

125
00:08:17,350 --> 00:08:19,840
The number equals.

126
00:08:23,870 --> 00:08:27,230
Three point something just like this.

127
00:08:27,560 --> 00:08:34,270
Now, if I use the round function from the math object, it is just going to round it to four.

128
00:08:35,060 --> 00:08:41,630
I could use the floor or the CEO methods, but still, it's not exactly what I want because maybe I

129
00:08:41,630 --> 00:08:45,170
just want to round this number to two decimal places.

130
00:08:45,470 --> 00:08:50,780
So in order to do this, we can call the variable my number.

131
00:08:50,900 --> 00:08:54,410
So now it's just a different way of writing it.

132
00:08:55,160 --> 00:09:03,950
So we just use the name of the variable and then a dot and then we can write to fix it, which is the

133
00:09:03,950 --> 00:09:05,330
name of this method.

134
00:09:05,660 --> 00:09:13,030
And inside here, we just informed the number of decimal places we want you if we don't write anything

135
00:09:13,040 --> 00:09:17,090
here is just going to round to no decimal places.

136
00:09:17,300 --> 00:09:21,270
If we write to, then it's going to round to two decimal places.

137
00:09:21,290 --> 00:09:22,570
Three, four.

138
00:09:22,820 --> 00:09:24,910
We can choose anything we want here.

139
00:09:25,250 --> 00:09:31,220
So at this point, you might be getting a bit confused because with the math object, we just wrote

140
00:09:31,220 --> 00:09:32,040
it like this.

141
00:09:32,060 --> 00:09:34,700
So math dot round.

142
00:09:34,940 --> 00:09:37,490
And then we place the number inside.

143
00:09:37,820 --> 00:09:41,210
So in this example, we would just write it like this.

144
00:09:41,330 --> 00:09:43,990
So math dot round.

145
00:09:44,360 --> 00:09:46,310
And then inside it.

146
00:09:47,440 --> 00:09:50,790
We are going to put our variable, so my number.

147
00:09:51,570 --> 00:09:53,280
So we would write it like this.

148
00:09:53,610 --> 00:09:57,060
And this is a different way of writing it.

149
00:09:57,330 --> 00:10:03,930
So my suggestion to you is that you don't worry about this at the moment because all of these things

150
00:10:04,500 --> 00:10:06,690
are going to be learned naturally.

151
00:10:07,440 --> 00:10:09,620
You don't have to understand everything.

152
00:10:09,630 --> 00:10:10,740
Why this one?

153
00:10:10,770 --> 00:10:11,880
You write it like this.

154
00:10:11,880 --> 00:10:12,690
Why this one?

155
00:10:12,690 --> 00:10:13,950
You write it like that.

156
00:10:14,370 --> 00:10:20,790
The intention here is just to get started getting comfortable with JavaScript writing code.

157
00:10:21,060 --> 00:10:25,260
And then you see that you won't have any trouble understanding these things.

158
00:10:25,590 --> 00:10:25,910
All right.

159
00:10:25,920 --> 00:10:28,040
So moving on now.

160
00:10:28,120 --> 00:10:33,990
We are going to talk about incremental operators, but this video is getting a bit too long.

161
00:10:34,000 --> 00:10:38,390
So I'm going to stop it here and we're going to continue in the next video.
