Created
August 2, 2021 08:07
-
-
Save artturijalli/ee844e97ff202bcdf3e070533dfc8a19 to your computer and use it in GitHub Desktop.
This file contains 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
function weekDay(dayNum) { | |
if (dayNum < 1 || dayNum > 7) { | |
throw 'InvalidDayNumber' | |
} else { | |
return ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'][dayNum - 1]; | |
} | |
} | |
try { // Try to run the following | |
let day = weekDay(8); | |
console.log(day); | |
} | |
catch (e) { // catch an error if the above try failed | |
let day = 'unknown'; | |
console.log(e); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment