write about the arithmetic operator in javascript?

JavascriptObject Oriented ProgrammingProgramming

JavaScript arithmetic operators include Addition, subtraction, Division, Multiplication. let's see some of them

1) Addition and modulus operators

 Live Demo

Example

<html>
<body>
<p id="add"></p>
<script>
   var tot = 0;
   var a = [1,2,3,4,5,6,7,8,9]
   for (var i = 0; i < a.length; i++) {
      if(a[i]%2 == 0) {
      tot += a[i]
      }
   }
   document.getElementById("add").innerHTML = tot;
</script>
</body>
</html>

Output

20


2) Multiplication operator

 Live Demo

Example

<html>
<body>
<p id="mul"></p>
<script>
   var pro = 1;
   var a = [1,2,3,4,5,6,7,8,9]
   for (var i = 0;i<a.length;i++) {
      pro *= a[i]
   }
   document.getElementById("mul").innerHTML = pro;
</script>
</body>
</html>

Output

362880


raja
Published on 22-May-2019 07:42:06
Advertisements