JavaScript Program to Display Greeting According to Time

Write a JavaScript program which welcomes the user by addressing

If user enters value in between 4 and 11 then it will get message "Hello, Good morning" If user enters value in between 12 and 17 then it will get message "Hello, Good afternoon" and so on.



Source Code
<html>
<head>
    <title>Display Greetings</title>
</head>
<body>
<script>
    var hrs = new Date().getHours();

    document.write("Time is " + hrs + "o' clock" + "<br>");
    if(hrs < 4)
        document.write("Hey, Good night");
    else if(hrs < 12)
        document.write("Hello, Good morning");
    else if(hrs < 17)
        document.write("Hello, Good afternoon");
    else 
        document.write("Hello, Good evening");
</script>
</body>
</html>
Output





"Coding Hub - Learn to code" app now available on Google Play Store