Complete the code to print a message for the number 2 using a switch statement.
let number = 2 switch number { case 1: print("One") case [1]: print("Two") default: print("Other") }
The case must match the value 2 to print "Two".
Complete the code to allow fallthrough in Swift switch cases.
let number = 1 switch number { case 1: print("One") [1] case 2: print("Two") default: print("Other") }
In Swift, to explicitly allow fallthrough to the next case, you must use the fallthrough keyword.
Fix the error in the switch statement by adding the correct keyword to allow fallthrough.
let number = 1 switch number { case 1: print("One") [1] case 2: print("Two") default: print("Other") }
In Swift, to explicitly allow fallthrough to the next case, you must use the fallthrough keyword.
Fill both blanks to create a switch that prints 'Low' for 1 or 2, and 'High' for 3 or 4.
let number = 3 switch number { case [1], [2]: print("Low") default: print("High") }
Cases can match multiple values separated by commas. Here, 1 and 2 print 'Low'.
Fill all three blanks to create a switch that prints 'Weekend' for Saturday and Sunday, and 'Weekday' otherwise.
let day = "Sunday" switch day { case [1], [2]: print("Weekend") default: print("[3]") }
The weekend days are Saturday and Sunday, and the default prints 'Weekday'.