switch cases fall-through to a common default. - Javascript Statement

Javascript examples for Statement:switch

Description

switch cases fall-through to a common default.

Demo Code

ResultView the demo in separate window

<html>
<body>

<button onclick="myFunction()">Test</button>

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

<script>
function myFunction() {//from   w w w  . j  a  v a  2  s  .co  m
    var text;
    switch (new Date().getDay()) {
        case 1:
        case 2:
        case 3:
        default:
            text = "Looking forward to the Weekend";
            break;
        case 4:
        case 5:
            text = "Soon it is Weekend";
            break;
        case 0:
        case 6:
            text = "It is Weekend";
    }
    document.getElementById("demo").innerHTML = text;
}
</script>

</body>
</html>

Related Tutorials