Switch with string value : Switch « Language Basics « JavaScript DHTML






Switch with string value

 


<html>
<head>
<title></title>
</head>
<body>
<script type="text/javascript">

var inputName = prompt("Please enter your name:");
switch(inputName) {
    case "Tom":
        document.write("Welcome " + inputName);
        break;
    case "Name":
        document.write("Name");
        break;
    default:
        document.write("default:" + inputName);
}

</script>
</body>
</html>

   
  








Related examples in the same category

1.Switch statement
2.The switch Statement
3.Another switch Statement
4. The switch Construction in Action
5.Use switch with true false value
6.Switch based on integer value