Return to Kroll Design home page

JavaScript Tutorials

 
« Return

switch statement

Make sure to include the "break" command if you want the switch statement to exit once a match is found:

Code:

<script type="text/javascript">
//<![CDATA[
time_zone = "central";

switch (time_zone) {
  case "eastern": {
    document.write("So you're an east coast type, eh?");
    break;
    }
  case "central": {
    document.write("How's that midwestern weather been lately?");
    break;
    }
  case "mountain": {
    document.write("Are you a mountain man, or a mountain woman?");
    break;
    }
  case "pacific": {
    document.write("A pacifist, I see.");
    break;
    }
  default: {
    document.write("Where are you from, anyway?");
    }
}
//]]>
</script>

Output:



 
« Return


©2012 Kroll Design    info@KrollDesign.net    781.910.3694
Last modified: 12/31/1969 7:00 PM