Edit

JavaScript Switch

The switch case is used to check a variable against a series of values until it finds a match. If there is nothing find then default condition will be used.

Syntax-:

switch(a){
    case value1:
        // Code to be executed if a === value1
        break;
    case value2:
        // Code to be executed if a === value2
        break;
    ...
    default:
        // Code to be executed if a is different from all values
}

Example of Code

<script>
var d = new Date();
//Notice: The getDay() method returns the day of the week (from 0 to 6) for the specified date.
switch(d.getDay()) {
    case 0:
        document.write("Today is Sunday.");
        break;
    case 1:
        document.write("Today is Monday.");
        break;
    case 2:
        document.write("Today is Tuesday.");
        break;
    case 3:
        document.write("Today is Wednesday.");
        break;
    case 4:
        document.write("Today is Thursday.");
        break;
    case 5:
        document.write("Today is Friday.");
        break;
    case 6:
        document.write("Today is Saturday.");
        break;   
    default:
        document.write("No information available for that day.");
        break;
}
</script>

Output