JavaScript Switch Case Statement Example

Example

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>JavaScript Switch Case</title>
</head>
<body>
<pre>  <!-- Use pre element for work document.writeln() method -->
<script>
var weekname = "wednesday";
switch (weekname) {
    case "monday":
        document.writeln("Monday working day.");
        break;
    case "tuesday":
        document.writeln("Tuesday working day.");
        break;
    case "wednesday":
        document.writeln("Wednesday government holiday.");
        break;
    case "thursday":
        document.writeln("Thursday working day.");
        break;
    case "friday":
        document.writeln("Friday is a last working day of the week.");
        break;
    case "saturday":
        document.writeln("Saturday week end.");
        break;
    case "sunday":
        document.writeln("Sunday week end.");
        break;
    default:
        document.writeln("No any case found.");
        // last line end of the case statement, no need to write break; keyword 
}
</script>
</pre>
</body>
</html>

Run it...   »

Example Result