Okay in this video I want to talk about numbers and math.
And first off numbers and a lot of programming languages you sort of have to differentiate between integers
and floats and an integer is just like a whole number.
Right.
Forty one.
Twelve.
One eleven.
Whatever a float is like a decimal.
Right.
Nineteen ninety five.
Twenty nine ninety five.
Twenty nine ninety nine.
Right.
So most programming languages you have to sort of tell the system what data type you're using an integer
or float.
Not so with JavaScript javascript just kind of figures everything out so you don't have to worry about
declaring a specific type for your numbers.
And that's cool.
So there is this video I want to spend a few minutes talking about math.
Math is really really easy and use math operators and the math operators are a plus minus division multiplication
exponents modulus.
If you don't know what the modulus says that finds the remainder will look at that in just a minute.
So to use those you use him just like you would math in any way.
So let's come down here and instead of first name let's just go to plus two and remember with JavaScript
he doesn't care about whitespace so you can type it like that if you want.
I like to use spaces just to make it easier to read things so please save this.
This should print out two plus two into our demo area here.
When we get four so it's really just that easy to do math in in JavaScript which is very cool so if
we go to minus two we get zero two times two should be four four two divided by two should be one two
goes into two one time and exponents two to the second parallel go to the to the third power.
So that's two times two times two.
Right.
Remember exponents back from grade school math.
If we save this and run it two times two is four times two should be eight.
Cool.
And finally let's look at this modulus.
Let's go 10 modulus two.
So what this does is it divides 10 by two which is five and then it returns the remainder.
So there is no remainder because 10 is divisible by 2.
So two goes into 10 five times with no remainder.
So if we save this and run it we'll get zero because there's no remainder on the other hand if we change
this to three three goes into 10 three times three times three is nine.
Right.
With one leftover ten minus nine is one.
So you know if you think back to like division when you're a kid when you did long division on paper
you would put the little remainder if you did that or not.
But so now Lori turn 1.
So this is a cool way of finding if numbers are divisible.
So you know 10 is not divisible by three without a remainder.
So that's kind of cool.
So math is just that easy.
And one more thing to keep in mind when it comes to math is order of operations is important.
If you remember back to grade school math.
Order of operations is the order that you do different things.
So if we have two plus three times four what is this going to be.
Is it gonna be two plus three which is five times four is 20 20 or is it going to be three times four
is twelve plus two is 14.
What do you think this is going to be.
Well it's going to be 14.
If we save this and reload boom we get 14 and that's because of order of operations in order of operations
in math.
This is not a programming thing.
This is not a javascript things it's just a math thing.
And in math order of operations multiplication is more important than addition.
So you do you as do multiplication first.
Same thing with Division.
You know we went 20 divided by four goes in five times plus two.
It's going to be seven.
So this gets done first and then this gets done second.
So if you don't remember order of operations I don't really remember it either.
I remember basic things like multiplication is more important but you know you might have to look that
up you can do a google search do order of operations to see because you know a lot of times in programming
you will have long strings of math like this in order of operations becomes important.
So most of the times in that case you'll do something like this.
So let's change this back.
Let's go three.
So this is three times in when you use parentheses whatever's in the parentheses gets done first because
in math order of operations parentheses are the most important thing at least in this state right here.
So we would go three times for his twelve plus two is 14 reload just to make sure and yes 14.
So you know when in doubt use parentheses or just look up your math order of operations.
So math can be done with numbers like this.
You can also use variables so we can go numb and square one equals 10 underscore 2 equals 2.
And then over here we can go numb underscore one times underscore or two.
So it's gonna be two times ten save.
This should be 20.
Well just like that.
So doesn't really matter if you use numbers or assign variables and we put these in there.
You see sometimes you can get away with not using semicolons on the end of your lines like that but
it's always a good idea to put them on there.
Sometimes I get sloppy.
But anyway so that's very very cool.
One last thing I want to look at very quickly you can increment using a double plus sign and you can
decrement decrease using a double negative sign.
And it's important where you put those.
So like if we went let's just get rid of num to here and if we went numb underscore one plus plus.
All right.
So we're assigning 10 into this variable num underscore one in our incrementing it by one and then we're
printing it out to the screen.
So boom.
Now we get 11 which is exactly what we should have 10 Plus 1.
We do the same thing with double negative.
Now this should be nine.
So that's kind of cool.
Now it is important.
Like I said where you put this for instance if we got rid of this line and instead incremented it right
here.
Check this out.
Boom it's still 10.
Why didn't it incremented.
Well it incremented it after.
Because the plus plus is after if we if we put the plus plus before and do this now it works right.
Because we'll check this out if we do it like this and then we put another line here.
It'll work this way when we get 11 because what's going on here is it's it's incrementing it after this
has already been printed to the screen.
So we're reading this line.
It says OK put this out on the screen put num 1 out onto the screen so it puts num 1 out on the screen.
And then after it does that it increments it.
That's what before does.
On the other hand if it's coming along it's reading this.
OK.
Document get Elman I.D. 0 increment this increment what increment this variable.
OK.
Boom.
And it does it.
So where you put the plus plus and minus minus is important to sort of keep that mine.
So that's math very basic math obviously can get into much more difficult math in javascript but that's
just the basic math I want to talk about in this video in the next video going to look at assignment
operators.