Add value within 1000 which can be divided by 3 or 5 or 7 - Javascript Operator

Javascript examples for Operator:Arithmetic Operator

Description

Add value within 1000 which can be divided by 3 or 5 or 7

Demo Code

ResultView the demo in separate window

<html>
   <head></head>
   <body> 
      <div id="resultsDiv"> 
         <h3>Results Here:</h3> 
      </div> 
      <script type="text/javascript">
    var sum = 0;//from ww w  .ja va 2s .c  o  m
    var resultsDiv = document.getElementById('resultsDiv');
    for (var i = 0; i < 1000; i++) {
      if (i % 3 === 0 || i % 5 === 0 || i % 7 === 0) {
        sum += i;
      }
      resultsDiv.innerHTML += 'The sum is' + " " + sum + "<br />";
    }
  
      </script>  
   </body>
</html>

Related Tutorials