JavaScript Dynamic Greeting. Fun project for beginner

JavaScript Dynamic Greeting. Fun project for beginner
0

#1

I build a fun coding project for beginner level who love JavaScript. Here: https://codepen.io/a2-zubair/pen/VzNgbz
I hope you will enjoy it. Have fun and happy coding :slight_smile:


#2

Another approach to the greetings function for this project:

function greetings(){
  var timesOfDay = {Morning: [0,12], Afternoon: [12,17], Evening: [17,20], Night: [20,24]};
  var hour = new Date().getHours();
  for (var when in timesOfDay) {
    if (hour >= timesOfDay[when][0] && hour < timesOfDay[when][1]) return when; 
  }
}