Advertisement
Guest User

Untitled

a guest
Mar 28th, 2015
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. /* Declaring Global Variables */
  2. var n;
  3. var sumOfThree = 0;
  4. var sumOfFive = 0;
  5.  
  6. /* Declaring Arrays */
  7. multiplesOfThree = [];
  8. multiplesOfFive = [];
  9.  
  10. /* Finding how many numbers < 1000 divide evenly by three and five then adding them to my arrays*/
  11.  
  12. console.log("Let's calculate how many numbers divide evenly by three and five in the number one thousand.");
  13. console.log("Calculating...");
  14.  
  15. for(n = 0; n < 1000; n ++) {
  16. if(n % 3 === 0) {
  17. multiplesOfThree.push(n);
  18. }
  19. }
  20.  
  21. for(n = 0; n < 1000; n ++) {
  22. if(n % 5 === 0) {
  23. multiplesOfFive.push(n);
  24. }
  25. }
  26.  
  27. */Letting the User know how many multiples of three exist */
  28.  
  29. console.log()
  30. console.log("There are " + multiplesOfThree.length + " multiples of three in the number one thousand.");
  31.  
  32. /* Letting the user know how many multiples of five exist */
  33.  
  34. console.log()
  35. console.log("There are " + multiplesOfFive.length + " multiples of five in the number one thousand.");
  36. console.log()
  37.  
  38. /*Letting the User know the sum of the number of multiples*/
  39.  
  40. console.log("Let's get the sum of the number of multiples.");
  41. console.log("Calculating...");
  42. console.log(multiplesOfThree.length + multiplesOfFive.length);
  43. console.log()
  44.  
  45. /* Letting the user know the sum of all the three multiples*/
  46. console.log("Let's get the sum of all the three multiples")
  47. console.log("Calculating... ");
  48. for (i=0; i < multiplesOfThree.length; i++) {
  49.  
  50. sumOfThree += multiplesOfThree[i];
  51.  
  52. }
  53. console.log(sumOfThree);
  54. console.log()
  55.  
  56. /* Letting the User know the sum of all the five multiples */
  57.  
  58. console.log("Let's get the sum of five multiples")
  59. console.log("Calculating... ");
  60. for (i=0; i < multiplesOfFive.length; i++) {
  61.  
  62. sumOfFive += multiplesOfFive[i];
  63.  
  64. }
  65. console.log(sumOfFive);
  66. console.log()
  67.  
  68. /* Letting the user the added sum of all the three, five multiples */
  69.  
  70. console.log("Let's add these two sums together")
  71. console.log("Calculating... ");
  72. var sumOfBoth = sumOfFive + sumOfThree;
  73. console.log(sumOfBoth);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement