Skip to content

Instantly share code, notes, and snippets.

@digitalconceptvisuals
Created July 30, 2020 18:04
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 digitalconceptvisuals/ccb41b352d92c7601981b1f6628c5c4e to your computer and use it in GitHub Desktop.
Save digitalconceptvisuals/ccb41b352d92c7601981b1f6628c5c4e to your computer and use it in GitHub Desktop.
function dayName(day) {
// Use an array instead of switch
const dayNames =
["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
// Is the day value between 1-7?
if (day < 1 || day > 7)
throw 'Invalid day number';
// Array starts with 0, Mon->1
return dayNames[day-1];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment