Question:

What output will be produced by the code below?

func fizzbuzz(number: Int) -> String {
    switch (number % 3 == 0, number % 5 == 0) {
    case (true, false):
        return "Fizz"
    case (false, true):
        return "Buzz"
    case (true, true):
        return "FizzBuzz"
    default:
        return String(number)
    }
}

print(fizzbuzz(number: 15))

Correct answer: "FizzBuzz".

Explanation: The fizzbuzz() method creates a tuple of two booleans. The first boolean is true if the numberparameter is evenly divisible by 3, and the second is true if it's evenly divisible by 5. The code uses 15, so the tuple will be (true, true), and thus will print FizzBuzz.

 


Keywords:

© 2017 QuizBucket.org