“Switch case javascript” Kode Jawaban

Switch case javascript

switch(expression) {
  case x:
    // code block
    break;
  case y:
    // code block
    break;
  default:
    // code block
}
Grotesque Grebe

Pernyataan sakelar javascript beberapa kasus

//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"
Grepper

Format kode kasus sakelar javascript

switch(type) {
	case "SomeString":
		// Functionality
		break;
	case "OtherString":
		// Functionality
		break;
	default:
		// Functionality
		break;
}
Nathan uses Linux

sakelar JavaScript

let x = 3;

switch(x) {
  case 1:
    console.log("You entered 1");
    break;
  case 2:
    console.log("You entered 2");
    break;
  default:
    console.log("You entered: "+ x);
}
The Cat Coder

Beralih JS

switch (expr) {
  case 'Oranges':
    console.log('Oranges are $0.59 a pound.');
    break;
  case 'Apples':
    console.log('Apples are $0.32 a pound.');
    break;
  case 'Bananas':
    console.log('Bananas are $0.48 a pound.');
    break;
  case 'Cherries':
    console.log('Cherries are $3.00 a pound.');
    break;
  case 'Mangoes':
  case 'Papayas':
    console.log('Mangoes and papayas are $2.79 a pound.');
    break;
  default:
    console.log('Sorry, we are out of ' + expr + '.');
}

console.log("Is there anything else you'd like?");
Yucky Yak

JavaScript Kasus Siwtch

const expr = 'Papayas';
switch (expr) {
  case 'Oranges':
    console.log('Oranges are $0.59 a pound.');
    break;
  case 'Mangoes':
  case 'Papayas':
    console.log('Mangoes and papayas are $2.79 a pound.');
    // expected output: "Mangoes and papayas are $2.79 a pound."
    break;
  default:
    console.log(`Sorry, we are out of ${expr}.`);
}
Tarik

Jawaban yang mirip dengan “Switch case javascript”

Pertanyaan yang mirip dengan “Switch case javascript”

Lebih banyak jawaban terkait untuk “Switch case javascript” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya