Conditional Programs

If Else usage in program


<!DOCTYPE html>
<html>
<body>

<p>
    If time is less than 12pm it will show "Good Morning". <br> <br>
    else it will show "Good Afternoon".
</p>

<button onclick="Function()"> Click Me </button>

<p id="demo" > </p>

<script>
    function Function() {

      var x = "";
      var time = new Date().getHours();

      if (time < 12) {

        x = "Good Morning";

      } else {

        x = "Good Afternoon";

      }

      document.getElementById("demo").innerHTML = x;
    }
</script>

</body>
</html>