Advertisement
Guest User

Simple Javascript Function

a guest
Dec 15th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. // make a loop that goes from 1 to 100
  2. for ( var num = 1; num < 101; num ++ ) {
  3.  
  4. // check if the number is divisible by 3 or 5
  5. var checkForThree = num % 3;
  6. var checkForFive = num % 5;
  7.  
  8. // if the number is divisible by both 3 and 5, then print FizzBuzz
  9. if ( (checkForThree == 0) && (checkForFive == 0) )
  10. console.log( "FizzBuzz");
  11.  
  12. // if the number is divisible by 3, then print Fizz
  13. else if (checkForThree == 0)
  14. console.log( "Fizz");
  15.  
  16. // if the number is divisible by 5, then print Buzz
  17. else if (checkForFive == 0)
  18. console.log( "Buzz");
  19.  
  20. // otherwise just print the number
  21. else
  22. console.log( num );
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement