Last active
October 11, 2024 13:51
-
-
Save TheMuellenator/ceed75150b5f7127c8bf38b3564e7ca3 to your computer and use it in GitHub Desktop.
iOS repl.it - Switch Challenge Solution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
////Don't change this | |
var aNumber = Int(readLine()!)! | |
func dayOfTheWeek(day: Int) { | |
//Write your code inside this function. | |
switch day { | |
case 1: | |
print("Monday") | |
case 2: | |
print("Tuesday") | |
case 3: | |
print("Wednesday") | |
case 4: | |
print("Thursday") | |
case 5: | |
print("Friday") | |
case 6: | |
print("Saturday") | |
case 7: | |
print("Sunday") | |
default: | |
print("Error") | |
} | |
} | |
//Don't change this | |
dayOfTheWeek(day: aNumber) |
////Don't change this
var aNumber = Int(readLine()!)!
func dayOfTheWeek(day: Int) {
//Write your code inside this function.
switch(day) {
case 1:
print("Monday")
case 2:
print("Tuesday")
case 3:
print("Wednesday")
case 4:
print("Thursday")
case 5:
print("Friday")
case 6:
print("Saturday")
case 7:
print("Sunday")
default:
print("Error")
}
}
This is how I did it, it was super fun.
var aNumber = 1 // you can insert your own number here
func dayOfTheWeek(day: Int) {
let daysArray = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
switch day {
case 1...daysArray.count:
print(daysArray[day - 1])
default:
print("Error")
}
}
dayOfTheWeek(day: aNumber)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.