Edit This Code:
See Result »
<!DOCTYPE html> <html> <body> <p>Click the button to get a time-based greeting:</p> <button onclick="myFunction()">Try it</button> <p id="demo"></p> <script> function myFunction() { var greeting; var time = new Date().getHours(); if (time < 10) { greeting = "Good morning"; } else if (time < 20) { greeting = "Good day"; } else { greeting = "Good evening"; } document.getElementById("demo").innerHTML = greeting; } </script> </body> <!-- Mirrored from www.w3schools.com/js/tryit.asp?filename=tryjs_elseif by HTTrack Website Copier/3.x [XR&CO'2014], Sun, 13 Mar 2016 11:03:04 GMT --> </html>
Result: