JavaScript Operators...what are they?

A JavaScript operator causes the JavaScript program to do something to variables.  Specifically, an arithmetic operator allows an arithmetic operation (such as addition +) to be preformed on variables.  You have already used the + operator from previous lessons.

var Val1 = 5;
var Val2 = 3;
var Ans;

   Ans = 5 + 3;

You need a JavaScript operator.

The JavaScript Operators...

The following table lists the common JavaScript arithmetic operators:

Using the JavaScript Arithmetic Operators

The following JavaScript program gives an example of the five common JavaScript arithmetic operators:

Now you got me thinking...

<script>
   var Num1 = 15;
   var Num2 = 3;
   var Addition_Answer;
   var Subtraction_Answer;
   var Multiplication_Answer;
   var Division_Answer;
   var Remainder_Answer;   
       Addition_Answer = Num1 + Num2;
       Subtraction_Answer = Num1 - Num2;
       Multiplication_Answer = Num1 * Num2;
       Division_Answer = Num1/Num2;
       Remainder_Answer = Num1 % Num2;
         document.write("Addition = ", Addition_Answer);
         document.write(" Subtraction = ", Subtraction_Answer);
         document.write(" Multiplication = ", Multiplication_Answer);
         document.write(" Division = ", Division_Answer);
         document.write(" Remainder = ", Remainder_Answer);
</script>

What do you think the output to the browser will be?

Copyright © 2000, AdamsonHouse.Ltd