Advertisement
asgfgh

Fizz Buzz JavaScript

Jun 28th, 2020
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”
  2.  
  3. var list = []
  4. for (var i = 1; i <= 100; i++) {
  5.     if (i % 3 == 0 && i % 5 == 0) list.push('Fizzbuzz');
  6.     else if (i % 3 == 0) list.push('Fizz')
  7.     else if (i % 5 == 0) list.push('Buzz')
  8.     else list.push(i)
  9. }
  10. console.log(list)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement