Skip to content

Instantly share code, notes, and snippets.

@matthewspear
Last active January 20, 2016 01:22
Show Gist options
  • Save matthewspear/be5b3d3b80f78a749884 to your computer and use it in GitHub Desktop.
Save matthewspear/be5b3d3b80f78a749884 to your computer and use it in GitHub Desktop.
Swift 2.0 FizzBuzz
//: Playground - noun: a place where people can play
func fizzBuzz(n: Int) -> String
{
let divThree = (n % 3 == 0)
let divFive = (n % 5 == 0)
var numberName = ""
if (divThree && divFive)
{
numberName += "FizzBuzz"
}
else if (divFive)
{
numberName += "Buzz"
}
else if (divThree)
{
numberName += "Fizz"
}
else
{
numberName += "\(n)"
}
return numberName
}
var fizzBuzzString = ""
for n in 1...100
{
fizzBuzzString += fizzBuzz(n)
fizzBuzzString += ", "
}
print(fizzBuzzString)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment