Created
September 9, 2014 06:58
-
-
Save leek/3f175f9bde96c6bb66b3 to your computer and use it in GitHub Desktop.
FizzBuzz solutions in various languages.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for (var i = 1; i <= 100; i++) { | |
if (i % 15 === 0) { | |
console.log('FizzBuzz'); | |
} else if (i % 3 === 0) { | |
console.log('Fizz'); | |
} else if (i % 5 === 0) { | |
console.log('Buzz'); | |
} else { | |
console.log(i); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
foreach (range(1, 100) as $num) { | |
if ($num % 15 === 0) { | |
echo 'FizzBuzz'; | |
} elseif ($num % 5 === 0) { | |
echo 'Buzz'; | |
} elseif ($num % 3 === 0) { | |
echo 'Fizz'; | |
} else { | |
echo $num; | |
} | |
echo PHP_SAPI === 'cli' ? PHP_EOL : '<br>'; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for num in 1..100 do | |
if num % 15 == 0 | |
puts "FizzBuzz" | |
elsif num % 5 == 0 | |
puts "Buzz" | |
elsif num % 3 == 0 | |
puts "Fizz" | |
else | |
puts num | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment