Arithmetic operators are used to perform arithmetic on numbers.
Both constants and variables.
This chart provides a quick overview of the different operators that can be used.
Now let's go over some examples to see how each one works.
We'll begin by adding two numerical values
in between our open and close script tags.
We'll create a variable called X the value of x will be 100 plus 50
next we'll create
our get element by I.D.
and the idea will be the word add that we'll go ahead and create the paragraph that will contain the
output value.
Let's go ahead and save our file and previewed in our web browser and we can see that we get the value
one hundred and fifty which is the correct value.
Now let's go ahead and perform another calculation this time we'll add two values and multiply the result
by the value of another variable
so let's go ahead and define two variables that variable a which will equal three variable B which will
equal 20 plus 30 multiplied by a.
So in this case it'll be multiplied by three
now we'll just create our output and we'll call the I.D. add 2 and we'll display the result underneath
our first calculation.
Then we'll save the file and refresh our web browser
so here we have once again one hundred and fifty output.
So that would be 20 plus 30 which is 50 multiplied by three which equates to one hundred and fifty.
This next example will subtract two values
called a variable C and we'll do one hundred minus 50.
And this time we'll give it the I.D. sub and we'll output the result at the bottom of our other two
calculations
and then we have it.
So that's how we multiply add and subtract.