Answers for "switch case javascript"

155

switch case javascript

switch(expression) {
  case x:
    // code block
    break;
  case y:
    // code block
    break;
  default:
    // code block
}
Posted by: Guest on February-21-2020
31

switch javascript

switch (a) {
    case 1:
        alert('case 1 executed');
        break;
    case 2:
        alert("case 2 executed");
        break;
   case 3:
        alert("case 3 executed");
        break;
    case 4:
        alert("case 4 executed");
        break;
    default:
        alert("default case executed");
}
Posted by: Guest on March-23-2020
78

javascript switch

//javascript multiple case switch statement
var color = "yellow";
var darkOrLight="";
switch(color) {
    case "yellow":case "pink":case "orange":
        darkOrLight = "Light";
        break;
    case "blue":case "purple":case "brown":
        darkOrLight = "Dark";
        break;
    default:
        darkOrLight = "Unknown";
}

//darkOrLight="Light"
Posted by: Guest on July-31-2019
7

Javascript switch case code format

switch(type) {
	case "SomeString":
		// Functionality
		break;
	case "OtherString":
		// Functionality
		break;
	default:
		// Functionality
		break;
}
Posted by: Guest on May-25-2020
6

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");
}
Posted by: Guest on August-10-2020
0

switch case javascript

const pet = "dog";

if (pet === "lizard") {
  console.log("I own a lizard");
} else if (pet === "dog") {
  console.log("I own a dog");
} else if (pet === "cat") {
  console.log("I own a cat");
} else if (pet === "snake") {
  console.log("I own a snake");
} else if (pet === "parrot") {
  console.log("I own a parrot");
} else {
  console.log("I don't own a pet");
}
Posted by: Guest on August-13-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language