In this video.
Let's begin with the arithmetic operators.
And this includes addition, subtraction, multiplication and division.
Back to Visual Studio code.
Since this is a new concept, I'm going to create a different folder for it and I'm going to copy and
paste this one and rename this one to.
Operators.
And inside here I'm going to remove all the JavaScript code and I'm going to rename this one to JavaScript
operators.
Great.
So now let's open this one.
And mine has opened here.
Let me reopen this as that.
Now we have operators.
So back to JavaScript.
Let me close this and let's begin with the addition operator.
And I'm going to add the comment here to make our life easier as that.
And up here I'm going to add the arithmetic operators.
And let's begin with the addition.
Let's say that you have five apples.
And then you got ten more.
How are you going to transform this one into code?
Meaning we want to find the final result.
So this how is going to work?
We are going to declare a variable and I'm going to use const and I will say apples on hand.
I mean the apples that you have.
Then later on you got ten more and that is apples received.
Is equal to ten.
So how are we going to perform operations on this?
Guys, take note.
We have started thinking like a programmer.
Because we are transforming a sentence.
Like if a person has five apples and then the person got ten more.
How are you going to calculate this using code?
And these are the steps.
So next step is that we need to save the value or the result into a variable.
So you need to be creative.
So here for the variable name, we are going to use descriptive.
So what we're going to be the variable name here is going to be total apples for the variables name.
We don't have right or wrong variable names, but it must be descriptive as we have spoke about.
For this one, we are going to add apples on hand and then we add the apples received.
Now we have the result of this one being assigned to total apples.
So if we console log the total apples, now let's see.
And we have 15.
And if I change this one to something like 90 and JavaScript is going to perform the calculations for
us, save it and let's see.
And we have 100.
And if I change this one to something like this, JavaScript is going to do the calculations for us
and we have it down here.
Then the next type of the arithmetic operator is the subtraction operator.
And for this one it is more descriptive.
So I'll paste it down here as that and it subtract one or more from another.
And even for this we can add more operations inside.
But let's go to the subtraction.
Let's say that there are 100 tickets for a concert and 45 are sold.
Then how many tickets are left?
How are you going to transform this one into code?
And here is a clue or here is an answer.
First of all, I'm going to declare a variable called total ticket and is equal to 100.
Then the ticket sold as concert ticket.
Sold is equal to 45.
Then the final result is going to be the ticket left and is equal to the total ticket minus the ticket
sold.
And if you console log the ticket left.
Let's look inside here and we have 55.
That is the subtraction for you.
Then the next type is the multiplication.
As the name implies, we used to multiply two or more numbers together.
And for this, let me add the question here so that you can think about it and transform that one into
code.
And I will paste it here as if a book cost $20 and someone buys 15, what will be the total cost for
this purchase?
So how are you going to transform this one into code?
And it goes like this const book cost.
Is equal to 20.
Then the books bought and that is the books bought is equal to 15.
Therefore, we are going to declare total cost.
Which is equal to the book cost.
Then multiply by the books bought.
And if we save this and check the total cost, we have 300.
Cool.
Right.
And the next one is the division operator.
And I will paste it here.
And let me give you the question that we are going to use to transform into code, and I'm going to
paste it here as that.
Great if there are 200 pages in a book and you read 40 pages per day, you will finish in how many days?
And that is the five days, right.
So how are you going to transform this one into code?
So let's see the logic.
First of all, read the question and then analyze the variables names.
And that is, if there are 200 pages, meaning total pages is equal to 200, then the next step is that
if you read 20 pages per day.
So here we are going to transform that one as pages.
Per day, which is equal to 40.
Therefore, how many days that you think you can finish.
So it's going to be as const days to finish.
As you can see here that my variable names are descriptive, so it's going to be the total pages divided
by the pages per day with this one.
If I check this to finish and we have five days to finish, then the next type is the module operator
and it's sometimes called the remainder.
So over here I'm going to paste that.
And this is a symbol.
It divides a number by another and retains the remainder.
When I say what is a remainder of three divided by 4 or 4 divided by three.
So over here, let me give you the scenario that we are going to transform into code.
So here if ten people are at a party and there are three pieces, each person gets three slices and
how many slices will be left and that is one slice will be left over.
So let's go ahead and transform this one into code.
And it goes like this const, how many people are the party?
So we're going to be as people at the party and they are ten people, so it's going to be as ten and
how many pizzas are at the party?
So here as pizzas at party.
Is equal to three.
Then how many were left?
So here I will say const slice left over.
Which is equal to the people at the party.
Then the percentage sign which represents the module and pizzas at the party.
So if I console log slice left over, we have one left.
And the next type is called the increment and decrement.
So let me paste the next type here called increment and decrement, meaning we are going to increase
a value by one.
So over here, let me paste the question here, which says that if a website has 1000 views and then
one person visit the website now has how many views?
That is 1001.
So how are we going transform this one into code?
And it goes like this.
Const let's deduce what is inside this.
And that is if a website has 1000 views.
So here we are going to represent this one as the current website views.
So it's going to be as current views is equal to 1000.
Then if I want to increase by one, I'm going to use the current views then plus plus.
So this is what we call the decrement with this one, if I receive it, as you can see, we have an
error.
I mean, tell me the issue here.
The problem here is that we are reassigning a value that has been declared with const.
Therefore we cannot reassign or update the value.
So for this case we are going to use let save it.
And now let's look at the current views and we have 1001 and this is the same as this which is plus
equal to one.
So that syntax is the same as this.
So with this one, if I check the current views, I still see the result and for this I can increase
by any value.
So for this one we are increasing by ten if I save it and check the result.
Here we have 1010.
Right.
That is the increment for you.
And the last type is called the decrement.
So I'm going to paste the comment here and this one is used to decrease by one and we have different
alternative where we can decrease by any amount.
So for this one, let me change this one to plus plus, if a basket player has 20 points and a point
is taken away, they now have how many points?
19 point.
So let's transform this one into code.
So here let and we're going to say basket.
Ballpoint.
And is equal to 20.
And here we are going to decrease by one and that is minus.
Minus as that with this one.
If I check the basketball point, we have 19 and for this one it is same as minus equal to one.
So the same as before.
If you check it out and we have the same result.
And for this I can decrease by any value.
And let's see, we have -980.
Great.
So these are the examples of the arithmetic operators.
Let's continue in the next video.