Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <title>The Standard FizzBuzz In Javascript</title>
- </head>
- <body>
- <h1>Fizz Buzz Excercise</h1>
- <script>
- /* REQUIREMENT:
- Write a program that uses console.log to print all the numbers from 1 to 100,
- with two exceptions. For numbers divisible by 3, print "Fizz" instead of the
- number, and for numbers divisible by 5 (and not 3), print "Buzz" instead.
- When you have that working, modify your program to print "FizzBuzz" for
- numbers that are divisible by both 3 and 5 (and still print "Fizz" or "Buzz"
- for numbers divisible by only one of those).
- */
- for(var i=1; i < 101; i++) {
- //FizzBuzz could be used using (i Mod 3 = 0 && i Mod 5 = 0) then
- //however this may require some compilers to then check for i mod 3 = 0 again, which is not redundant.
- if(i % 3 == 0){
- if(i % 5 == 0){
- console.log("FizzBUZZ")
- }else
- console.log("Fizz");
- }else if (i % 5 == 0) {
- console.log("Buzz");
- } else {
- console.log(i);
- }
- }
- </script>
- </body></html>
Add Comment
Please, Sign In to add comment