Conditional Programs

Switch Case usage in program



<!DOCTYPE html>
<html>
<body>

<h2> Click the button it will display what day is today. </h2>

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

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

<script>
    function Function() {

      var x;
      var d = new Date().getDay();

      switch (d) {
      case 0:
        x = "Today is Sunday";
        break;
      case 1:
        x = "Today is Monday";
        break;
      case 2:
        x = "Today is Tuesday";
        break;
      case 3:
        x = "Today is Wednesday";
        break;
      case 4:
        x = "Today is Thursday";
        break;
      case 5:
        x = "Today is Friday";
        break;
      case 6:
        x = "Today is Saturday";
        break;
      }

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

</body>
</html>