0
Can someone tell me which way I go wrong here?
let streetlight = ("green", "red") switch streetlight { case let ("red", "yellow") where "red" == "yellow": print("(\("red"), \("yellow")) still missing the green") case let ("green", "red") where "green" == "red": print("(\("green"), \("red")) still missing yellow") case let ("green", "yellow") where "green" == "yellow": print("(\("green"), \("yellow")) still missing red") default: print("you need to check Google") } thank you
2 odpowiedzi
+ 2
Remove quotes from around variable names and maybe give them less confusing names that don't conflict with the values of the tuple.
let streetlight = ("green", "red")
switch streetlight {
case let (a, b) where a == "yellow":
print("(\(a), \(b)) still missing the green")
case let (a, b) where a == "red":
print("(\(a), \(b)) still missing yellow")
case let (a, b) where a == "yellow":
print("(\(a), \(b)) still missing red")
default:
print("you need to check Google")
}
0
thank you so much. I was just thinking of that yesterday 🙏🏽