Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
function dayName(day) {
// Load the day names from a file
const dayNames = require('./weekday.json');
// Were there seven names in the array?
if (dayNames.length != 7)
throw 'Error in weekday.json';
// Is day value between 1-7?
if (day < 1 || day > 7)
throw 'Invalid day number';
// Array start 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