<!DOCTYPE html> <html> <body> <p>Click button to display a time-as per greeting:</p> <button onclick="myFunction()">Try it</button> <p id="demo"></p> <script> function myFunction() { var hour = new Date().getHours(); var greeting; if (hour < 18) { greeting = "Have a Good day prayag "; } else { greeting = "Good evening prayag"; } document.getElementById("demo").innerHTML = greeting; } </script> </body> </html>