Last active
July 1, 2017 01:45
-
-
Save dkliman/4a32b49b586c154e480479f1f96b9963 to your computer and use it in GitHub Desktop.
Swift Coding Challenges Chapter 2, Challenge 16: Fizz Buzz
This file contains hidden or 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
//Chapter 2: Numbers | |
//Challenge 16: Fizz Buzz | |
func fizzBuzz() { | |
for number in 1...100 { | |
let fizz = (number % 3 == 0) ? "Fizz " : "" | |
let buzz = (number % 5 == 0) ? "Buzz" : "" | |
let printableNumber = fizz + buzz == "" ? String(number) : "" | |
print ("\(printableNumber)\(fizz)\(buzz)") | |
} | |
} | |
fizzBuzz() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
now correctly formats "Fizz Buzz" when both appear.