Hey guys this video we're going to start to work with numbers and also the math object.
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
get this to 100.
Let's get to to 50 and I'm going to set.
Going to initialize a vowel variable.
OK because we're going to be basically mutating this variable as we go along.
All right and then down at the bottom here I just want to console log the val.
All right.
So first thing I want to look at is just basic math.
OK.
So simple math with numbers so we can say we'll take that well and we'll set it to number one plus two
and this is very easy.
Very simple stuff guys I know that but I do you know this is for beginners to advance so we need to
cover everything.
So we'll save that and obviously down here we're going to get 150.
All right so in addition to addition of course we can do it say multiplication save that we get five
thousand.
Let's do subtraction.
We get 50 let's do division.
We get two.
And let's do the modulus operator which will basically give us what's left over as a remainder.
So if we save that we get zero.
All right.
If I were to change this to let's say 60 and say we're going to get 40.
All right.
Now I using me I don't actually use this modulus that much.
But those are the basic math operators.
Now there's a math object we can use to do certain things like round get the absolute get get the power
of something generate random numbers things like that so we're going to take a look at that.
All right so let's take that vow and let's set that.
First of all I want to do math Daut pi.
So math is an object meaning that it has properties and methods.
OK.
A property is basically like an attribute and then a method is just a function.
Ok it's a function inside of a private inside of an object.
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
point 1 4 1 whatever.
We also have and there's there's a few other ones that I'm not going to mention that I've never even
thought about using this as ular as numbers so math thought me save that.
That gives us this number here and then we're going to look at some helpful methods.
All right.
So if you want a round number let's say value equals math.
Round
so round and let's do to say two point eight.
So that's going around 2 3.
If we do two point four that's going around to two.
Now there's going to be times when you want to specify if you want to round up or down.
So for that we have Seal and floor.
So for instance if we want to round up we'll do seal.
And even if we put two point four in here and save we're going to get three.
All right.
And then at the same time we have math thought floor where if we put two point eight and save we're
going to get two.
OK.
Now if we want to square something we can say the math Daut square root or s q r t.
So let's say we want to square 64 save we get a.
All right if we want to get the absolute number.
So say math thought abs that will give us the absolute numbers so if we put a negative number in here
it's going to give us the positive version of it which is the absolute version of it.
All right if we want to get the power of something we can say vowel equals math dog POW.
All right so let's say we want 8 to the second and save and we get 64 OK.
We also have min and max.
So let's say value equals math thought men.
And then this actually takes in some comma separated values so let's just put some random numbers in
here.
And we'll save and I'm just going to return whatever the minimum is and that's one and we can also put
negative numbers in here so obviously if I put negative two that's going to be the men.
OK and as you can probably guess we also have a max method.
So if I change this to Max and save we get 55 which is the max number.
All right.
So we also have a helpful method called random.
So math Daut random.
Now what this does is it gives us a random decimal.
So if I keep reload here you'll see it'll keep changing.
Now in a lot of cases you're going to want a random whole number.
So.
So just using math dot random isn't going to help you.
So a solution to this would be to say that all equals and we'll use the math thought random which will
generate a random decimal and then multiply it by the max number we want.
So let's say 20.
So if I go ahead and save this and we look down here this is going to give us a random number with a
decimal are between 0 and 19.
All right.
Now you're probably going to want from 1 to 20 so all you would do is just add on a 1 to that.
OK so now it will be 1 through 20 but you probably don't want the decimals.
So what you would do is wrap it in math for her.
All right so we're going to round it down so we'll go ahead and wrap that up.
The whole thing save.
And now we're going to get a random number between 1 and 20 Always.
All right so.
So this is something that you see it's very very common in javascript.
All right guys so in the next video we're going to work with strings.
So we're going to look at concatenation.
We're going to look at some of the different methods to change a string to upper case or to replace
something in a string to pluck something out of a string.
How to turn a string into an array things like that things that are used all the time in projects.
All right.
So I know that this stuff isn't as exciting as building something as building a project but it's all
fundamental knowledge that you need in order to be able to do that and actually understand what's going
on and not just do a code along you know so we will get into projects but we need to cover these fundamentals
first.
So that's it.
I will see you in the next video.