d
Amit DhamuSoftware Engineer
 

Time of day greeting

1 minute read 00000 views
const timeOfDayGreeting = (): string => {
  const hour = new Date().getHours()

  if (hour >= 5 && hour < 12) {
    return 'morning'
  } else if (hour >= 12 && hour < 17) {
    return 'afternoon'
  } else if ((hour >= 17 && hour <= 23) || hour < 5) {
    return 'evening'
  }
}

console.log(`Good ${timeOfDayGreeting()}, Amit`)