Complete the code to match the number 10 in the switch statement.
let number = 10 switch number { case [1]: print("Number is ten") default: print("Number is something else") }
The case must match the value 10 to print "Number is ten".
Complete the where clause to check if the number is even.
let number = 8 switch number { case let x where x [1] 2 == 0: print("Even number") default: print("Odd number") }
The modulo operator (%) checks the remainder. If remainder is 0 when divided by 2, the number is even.
Fix the error in the where clause to check if the number is positive.
let number = -3 switch number { case let x where x [1] 0: print("Positive number") default: print("Non-positive number") }
To check if a number is positive, it must be greater than 0.
Fill both blanks to check if the number is between 1 and 10 inclusive.
let number = 7 switch number { case let x where x [1] 1 && x [2] 10: print("Number is between 1 and 10") default: print("Number is out of range") }
The number should be greater than or equal to 1 and less than or equal to 10.
Fill both blanks to check if the number is odd and greater than 5.
let number = 7 switch number { case let x where x [1] 2 != 0 && x [2] 5: print("Odd number greater than 5") default: print("Other number") }
The modulo operator % checks oddness (not equal to 0), and > 5 checks if number is greater than 5.
