Reputation: 47
I'm trying to convert from below if-statement to switch statement but I'm keep getting error.
let meal = "breakfast"
if meal == "breakfast" {
print("Good morning!")
} else if meal == "lunch" {
print("Good afternoon!")
} else if meal == "dinner" {
print("Good evening!")
} else {
print("Hello!")
}
this was my switch statement:
switch meal {
let meal = "breakfast"
case 1:
print("Good morning!”)
case 2:
print("Good afternoon!")
case 3:
print("Good evening!")
}
Upvotes: 0
Views: 424
Reputation: 804
let meal = "breakfast"
switch meal {
case "breakfast":
print("Good morning")
case "lunch":
print("Good afternoon!")
case "dinner":
print("Good evening!")
default:
print("default case")
}
put this switch block in your code :)
Upvotes: 1