FizzBuzz code example
Example 1: hackerrank fizzbuzz javascript
for (i=1; i<=100; i++) {
console.log((i%3==0&&i%5==0)?"FizzBuzz":(i%3==0)?"Fizz" : (i%5==0)?"Buzz" : i);
}
Example 2: FizzBuzz
for (let i = 1, msg; i <= 100; i++, msg = '') {
if (!(i % 3)) msg += 'Fizz';
if (!(i % 5)) msg += 'Buzz';
console.log(msg || i);
}
Example 3: fizzbuzz python
def fizz_buzz(num):
if num % 3 == 0 and num % 5 == 0:
return "fizzBuzz"
elif num % 3 == 0:
return "fizz"
elif num % 5 == 0:
return "buzz"
else:
return num