PGSystemTester

FizzBuzz Javascript

Aug 3rd, 2018
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <html>
  2.  
  3.   <head>
  4.     <title>The Standard FizzBuzz In Javascript</title>
  5.  
  6.   </head>
  7.  
  8.   <body>
  9.     <h1>Fizz Buzz Excercise</h1>
  10.     <script>
  11.  
  12.     /* REQUIREMENT:
  13.      Write a program that uses console.log to print all the numbers from 1 to 100,
  14.      with two exceptions. For numbers divisible by 3, print "Fizz" instead of the
  15.      number, and for numbers divisible by 5 (and not 3), print "Buzz" instead.
  16.      When you have that working, modify your program to print "FizzBuzz" for
  17.      numbers that are divisible by both 3 and 5 (and still print "Fizz" or "Buzz"
  18.      for numbers divisible by only one of those).
  19.     */
  20.  
  21.       for(var i=1; i < 101; i++) {
  22.  
  23.  
  24.     //FizzBuzz could be used using (i Mod 3 = 0 && i Mod 5 = 0) then
  25.     //however this may require some compilers to then check for i mod 3 = 0 again, which is not redundant.
  26.         if(i % 3 == 0){
  27.  
  28.           if(i % 5 == 0){
  29.             console.log("FizzBUZZ")
  30.  
  31.           }else
  32.             console.log("Fizz");
  33.            
  34.           }else if (i  % 5 == 0) {
  35.             console.log("Buzz");
  36.  
  37.         } else {
  38.             console.log(i);
  39.         }
  40.       }
  41.     </script>
  42.   </body></html>
Add Comment
Please, Sign In to add comment