Skip to content

Instantly share code, notes, and snippets.

@artturijalli
Created August 2, 2021 08:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save artturijalli/ee844e97ff202bcdf3e070533dfc8a19 to your computer and use it in GitHub Desktop.
Save artturijalli/ee844e97ff202bcdf3e070533dfc8a19 to your computer and use it in GitHub Desktop.
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