“Case de commutation JS” Réponses codées

Case de commutation JS

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

Instruction JavaScript Switch plusieurs cas

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

commutateur 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

commutateur 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

Instruction JavaScript Switch

 switch (new Date().getDay()) {
  case 0:
    day = "Sunday";
    break;
  case 1:
    day = "Monday";
    break;
  case 2:
     day = "Tuesday";
    break;
  case 3:
    day = "Wednesday";
    break;
  case 4:
    day = "Thursday";
    break;
  case 5:
    day = "Friday";
    break;
  case 6:
    day = "Saturday";
}     

console.log(day);
Javasper

Casquer le boîtier JS

switch(expression) {
  case a:
    // case logic
    break;
  case b:
    // case logic
    break;
  default:
    // default logic
}
Deltanboi

Réponses similaires à “Case de commutation JS”

Questions similaires à “Case de commutation JS”

Plus de réponses similaires à “Case de commutation JS” dans JavaScript

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code