Skip to content

Instantly share code, notes, and snippets.

@karenying
Created October 16, 2020 19:30
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 karenying/fb0c0be4fb6c3d1e1b7b594b03d0bba8 to your computer and use it in GitHub Desktop.
Save karenying/fb0c0be4fb6c3d1e1b7b594b03d0bba8 to your computer and use it in GitHub Desktop.
const date = new Date();
const currHour = date.getHours();
let timeframe;
if (currHour >= 6 && currHour <= 11) {
timeframe = 'morning';
} else if (currHour >= 12 && currHour <= 16) {
timeframe = 'afternoon';
} else if (currHour >= 17 && currHour <= 20) {
timeframe = 'evening';
} else {
timeframe = 'night';
}
document.querySelector('#timeframe').innerHTML = timeframe;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment