switch statemnt javascript code example
Example 1: js switch case
switch(expression) {
case x:
break;
case y:
break;
default:
}
Example 2: javascript switch
let color = "black";
switch(color){
case "red":
console.log("color is red");
break;
case "white":
console.log("color is white");
break;
case "black":
console.log("color is black");
break;
default:
console.log("unknow color");
}
Example 3: switch javascript
switch (expressão) {
case valor1:
[break;]
case valor2:
[break;]
...
case valueN:
[break;]
default:
[break;]
}
Example 4: switch case in js
<html>
<body>
<script type = "text/javascript">
<!--
var grade = 'A';
document.write("Entering switch block<br />");
switch (grade) {
case 'A': document.write("Good job<br />");
case 'B': document.write("Pretty good<br />");
case 'C': document.write("Passed<br />");
case 'D': document.write("Not so good<br />");
case 'F': document.write("Failed<br />");
default: document.write("Unknown grade<br />")
}
document.write("Exiting switch block");
</script>
<p>Set the variable to different value and then try...</p>
</body>
</html>