<!-- JavaScript:Basics plus code snippet 9. --> <!-- Use of 'switch' statement structure with 'case' and 'break'. --> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <!-- Code source: http://www.justfigures.co.uk/ --> <!-- A resource for web developers using XHTML, CSS, JavaScript, PHP --> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>View code snippet page</title> </head> <body> <script language="JavaScript" type="text/javascript"> <!-- begin // declare and initialise variable in a single line var suitCase="holdall"; // a switch condition which can be an expression switch(suitCase){ case "travel": document.write("You have a travel suitcase."); break; case "vanity": document.write("You have a vanity suitcase."); break; case "overnight": document.write("You have a overnight suitcase."); break; case "holdall": document.write("You have a holdall suitcase."); break; // a default if none of the cases match default: document.write("Your case was not found here."); break; } // end --> </script> </body> </html>