1
00:00:00,830 --> 00:00:06,410
Hey guys this video we're going to start to work with numbers and also the math object.

2
00:00:06,420 --> 00:00:12,600
So what we're going to do here is we're going to set two numbers so I'll say Konst number one and let's

3
00:00:12,600 --> 00:00:15,060
get this to 100.

4
00:00:15,060 --> 00:00:20,810
Let's get to to 50 and I'm going to set.

5
00:00:20,830 --> 00:00:23,170
Going to initialize a vowel variable.

6
00:00:23,250 --> 00:00:27,650
OK because we're going to be basically mutating this variable as we go along.

7
00:00:27,840 --> 00:00:35,600
All right and then down at the bottom here I just want to console log the val.

8
00:00:35,760 --> 00:00:36,380
All right.

9
00:00:36,870 --> 00:00:39,600
So first thing I want to look at is just basic math.

10
00:00:39,740 --> 00:00:40,070
OK.

11
00:00:40,080 --> 00:00:54,410
So simple math with numbers so we can say we'll take that well and we'll set it to number one plus two

12
00:00:54,420 --> 00:00:55,580
and this is very easy.

13
00:00:55,580 --> 00:01:02,090
Very simple stuff guys I know that but I do you know this is for beginners to advance so we need to

14
00:01:02,090 --> 00:01:03,280
cover everything.

15
00:01:03,380 --> 00:01:07,360
So we'll save that and obviously down here we're going to get 150.

16
00:01:07,370 --> 00:01:15,420
All right so in addition to addition of course we can do it say multiplication save that we get five

17
00:01:15,420 --> 00:01:16,650
thousand.

18
00:01:17,330 --> 00:01:20,810
Let's do subtraction.

19
00:01:21,590 --> 00:01:25,200
We get 50 let's do division.

20
00:01:26,060 --> 00:01:26,970
We get two.

21
00:01:26,990 --> 00:01:32,540
And let's do the modulus operator which will basically give us what's left over as a remainder.

22
00:01:32,540 --> 00:01:34,830
So if we save that we get zero.

23
00:01:35,060 --> 00:01:35,390
All right.

24
00:01:35,390 --> 00:01:41,180
If I were to change this to let's say 60 and say we're going to get 40.

25
00:01:41,210 --> 00:01:41,590
All right.

26
00:01:41,630 --> 00:01:45,720
Now I using me I don't actually use this modulus that much.

27
00:01:45,950 --> 00:01:49,280
But those are the basic math operators.

28
00:01:49,280 --> 00:01:57,650
Now there's a math object we can use to do certain things like round get the absolute get get the power

29
00:01:57,650 --> 00:02:04,980
of something generate random numbers things like that so we're going to take a look at that.

30
00:02:05,030 --> 00:02:09,500
All right so let's take that vow and let's set that.

31
00:02:09,740 --> 00:02:11,860
First of all I want to do math Daut pi.

32
00:02:11,860 --> 00:02:16,270
So math is an object meaning that it has properties and methods.

33
00:02:16,280 --> 00:02:17,060
OK.

34
00:02:17,090 --> 00:02:22,960
A property is basically like an attribute and then a method is just a function.

35
00:02:23,000 --> 00:02:26,450
Ok it's a function inside of a private inside of an object.

36
00:02:26,480 --> 00:02:31,730
So pi as you can probably yes is just going to give us pi if I say that we're going to get that three

37
00:02:31,730 --> 00:02:34,310
point 1 4 1 whatever.

38
00:02:34,310 --> 00:02:40,010
We also have and there's there's a few other ones that I'm not going to mention that I've never even

39
00:02:40,010 --> 00:02:44,840
thought about using this as ular as numbers so math thought me save that.

40
00:02:44,840 --> 00:02:50,000
That gives us this number here and then we're going to look at some helpful methods.

41
00:02:50,000 --> 00:02:50,330
All right.

42
00:02:50,330 --> 00:02:55,320
So if you want a round number let's say value equals math.

43
00:02:55,400 --> 00:02:56,090
Round

44
00:02:58,850 --> 00:03:03,540
so round and let's do to say two point eight.

45
00:03:03,560 --> 00:03:05,730
So that's going around 2 3.

46
00:03:05,900 --> 00:03:10,230
If we do two point four that's going around to two.

47
00:03:10,430 --> 00:03:15,170
Now there's going to be times when you want to specify if you want to round up or down.

48
00:03:15,170 --> 00:03:18,280
So for that we have Seal and floor.

49
00:03:19,250 --> 00:03:24,130
So for instance if we want to round up we'll do seal.

50
00:03:24,770 --> 00:03:30,080
And even if we put two point four in here and save we're going to get three.

51
00:03:30,120 --> 00:03:30,620
All right.

52
00:03:30,620 --> 00:03:37,910
And then at the same time we have math thought floor where if we put two point eight and save we're

53
00:03:37,910 --> 00:03:39,270
going to get two.

54
00:03:39,830 --> 00:03:40,800
OK.

55
00:03:41,300 --> 00:03:50,780
Now if we want to square something we can say the math Daut square root or s q r t.

56
00:03:50,780 --> 00:03:55,300
So let's say we want to square 64 save we get a.

57
00:03:55,780 --> 00:03:59,000
All right if we want to get the absolute number.

58
00:04:00,290 --> 00:04:07,340
So say math thought abs that will give us the absolute numbers so if we put a negative number in here

59
00:04:07,340 --> 00:04:12,000
it's going to give us the positive version of it which is the absolute version of it.

60
00:04:12,050 --> 00:04:19,940
All right if we want to get the power of something we can say vowel equals math dog POW.

61
00:04:20,650 --> 00:04:30,530
All right so let's say we want 8 to the second and save and we get 64 OK.

62
00:04:30,560 --> 00:04:33,020
We also have min and max.

63
00:04:33,020 --> 00:04:38,000
So let's say value equals math thought men.

64
00:04:38,180 --> 00:04:44,270
And then this actually takes in some comma separated values so let's just put some random numbers in

65
00:04:44,270 --> 00:04:45,510
here.

66
00:04:49,230 --> 00:04:55,470
And we'll save and I'm just going to return whatever the minimum is and that's one and we can also put

67
00:04:55,470 --> 00:05:00,160
negative numbers in here so obviously if I put negative two that's going to be the men.

68
00:05:00,640 --> 00:05:04,890
OK and as you can probably guess we also have a max method.

69
00:05:04,890 --> 00:05:12,620
So if I change this to Max and save we get 55 which is the max number.

70
00:05:12,630 --> 00:05:12,980
All right.

71
00:05:12,980 --> 00:05:17,100
So we also have a helpful method called random.

72
00:05:18,040 --> 00:05:20,490
So math Daut random.

73
00:05:20,490 --> 00:05:24,830
Now what this does is it gives us a random decimal.

74
00:05:24,840 --> 00:05:28,200
So if I keep reload here you'll see it'll keep changing.

75
00:05:28,200 --> 00:05:32,130
Now in a lot of cases you're going to want a random whole number.

76
00:05:32,160 --> 00:05:32,520
So.

77
00:05:32,580 --> 00:05:36,970
So just using math dot random isn't going to help you.

78
00:05:37,050 --> 00:05:44,910
So a solution to this would be to say that all equals and we'll use the math thought random which will

79
00:05:44,910 --> 00:05:49,860
generate a random decimal and then multiply it by the max number we want.

80
00:05:49,860 --> 00:05:51,200
So let's say 20.

81
00:05:51,360 --> 00:05:57,750
So if I go ahead and save this and we look down here this is going to give us a random number with a

82
00:05:57,750 --> 00:06:02,570
decimal are between 0 and 19.

83
00:06:02,580 --> 00:06:02,930
All right.

84
00:06:02,940 --> 00:06:10,150
Now you're probably going to want from 1 to 20 so all you would do is just add on a 1 to that.

85
00:06:10,380 --> 00:06:15,270
OK so now it will be 1 through 20 but you probably don't want the decimals.

86
00:06:15,270 --> 00:06:20,320
So what you would do is wrap it in math for her.

87
00:06:20,370 --> 00:06:24,630
All right so we're going to round it down so we'll go ahead and wrap that up.

88
00:06:24,630 --> 00:06:26,070
The whole thing save.

89
00:06:26,160 --> 00:06:32,440
And now we're going to get a random number between 1 and 20 Always.

90
00:06:32,460 --> 00:06:32,970
All right so.

91
00:06:33,000 --> 00:06:37,440
So this is something that you see it's very very common in javascript.

92
00:06:37,440 --> 00:06:40,790
All right guys so in the next video we're going to work with strings.

93
00:06:40,800 --> 00:06:42,630
So we're going to look at concatenation.

94
00:06:42,630 --> 00:06:48,540
We're going to look at some of the different methods to change a string to upper case or to replace

95
00:06:48,540 --> 00:06:52,070
something in a string to pluck something out of a string.

96
00:06:52,370 --> 00:06:57,790
How to turn a string into an array things like that things that are used all the time in projects.

97
00:06:57,780 --> 00:06:58,380
All right.

98
00:06:58,470 --> 00:07:04,500
So I know that this stuff isn't as exciting as building something as building a project but it's all

99
00:07:04,500 --> 00:07:09,750
fundamental knowledge that you need in order to be able to do that and actually understand what's going

100
00:07:09,750 --> 00:07:15,750
on and not just do a code along you know so we will get into projects but we need to cover these fundamentals

101
00:07:15,750 --> 00:07:16,290
first.

102
00:07:16,290 --> 00:07:17,130
So that's it.

103
00:07:17,130 --> 00:07:18,560
I will see you in the next video.

