Code:
<!doctype html>
<html>
<head>
<title>Switch Statement</title>
<script type="text/javascript">
function checkAnimal()
{
Switch (document.frmAnimal.txtAnimal.value)
{
case "rabbit":
alert("Watch out, it's Elmer Fudd!")
break;
case "coyote":
alert("No match for the road runner - meep meep!")
break;
case "mouse":
alert("Watch out Jerry, here comes Tom!")
break;
default:
alert("Are you sure you picked an animal from a cartoon?");
}
}
</script>
</head>
<body>
<p>
Enter the name of your favorite type of animal that stars in a cartoon :
</p>
<form name="frmAnimal">
<input type="text" name="txtAnimal" /><br />
<input type="button" value="Check Animal" onclick="checkAnimal()" />
</form>
<p>Note that rabbit, coyote, and mouse will all get different responses.</p>
</body>
</html>