Greeting to the User According to the Time using JavaScript

Introduction

 
In this article, I will tell you how to “welcome” any user according to the time. i.e- if time is bellow 12 then it show “Good Morning, welcome to our website ”.if time is greater than 12 but less than 17 then it shows "Good AfterNoon, welcome to our website". if time is greater than 17 but less than 24 then it show "Good Evening, welcome to our website".
 
Code
  1. <html>  
  2.   
  3.   <body>  
  4.     <script>  
  5.     var welcome;  
  6.     var date = new Date();  
  7.     var hour = date.getHours();  
  8.     var minute = date.getMinutes();  
  9.     var second = date.getSeconds();  
  10.     if (minute < 10) {  
  11.       minute = "0" + minute;  
  12.     }  
  13.     if (second < 10) {  
  14.       second = "0" + second;  
  15.     }  
  16.     if (hour < 12) {  
  17.       welcome = "good morning";  
  18.     } else if (hour < 17) {  
  19.       welcome = "good afternoon";  
  20.     } else {  
  21.       welcome = "good evening";  
  22.     }  
  23.     document.write("<h2>" + "<font color='red'>" + welcome + "</font>" + " welcome to our website");  
  24.     document.write("<br>" + hour + ":" + minute + ":" + second);  
  25.     </script>  
  26.   </body>  
  27.   
  28. </html> 
Output is: