Skip to content

Instantly share code, notes, and snippets.

@jcefoli
Created October 24, 2019 20:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcefoli/f8c81994f2575eed5e640752742d669e to your computer and use it in GitHub Desktop.
Save jcefoli/f8c81994f2575eed5e640752742d669e to your computer and use it in GitHub Desktop.
[Powershell Interview Question] The FizzBuzz Problem: Write a program that prints the numbers 1 to 100. For multiples of 3, print "Fizz". For multiples of 5, print "Buzz". FOr multiples of both 3 and 5, print "FizzBuzz".
for ($x = 1; $x -le 100; $x++) {
$Output = ""
if ($x % 3 -eq 0) { $Output += "Fizz" }
if ($x % 5 -eq 0) { $Output += "Buzz" }
if ($Output -eq "") { $Output = $x }
Write-Output $Output
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment