Last active
January 20, 2016 01:22
-
-
Save matthewspear/be5b3d3b80f78a749884 to your computer and use it in GitHub Desktop.
Swift 2.0 FizzBuzz
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
//: 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