17 Haziran 2020 Çarşamba

switch Statement

Örnek - fall through
Şöyle yaparız
function testMyNumber(number) {
  switch (number) {
    case 6:
      return number+" is 6";
    case 3:
    case 4:
      return number+" is 3 or 4";

    case 9:
    case 10:
      return number+" is 9 or 10";
    default:
      return number+" is not in 3,4,6,9,10";
  }
};
Örnek
Şöyle yaparız.
var moyen = 9;

switch(true) {
  case (10 < moyen && moyen < 11.99):
    console.log("Acceptable");
    break;
  case (12 < moyen && moyen < 13):
    console.log("Souhaitable"); 
    break;
  case (14 < moyen && moyen < 15):
    console.log("Bien");
    break;
  case (moyen >= 16):
    console.log("Très bien");
    break;
  default:
    console.log("C'est pas un valide moyen !");
};

Hiç yorum yok:

Yorum Gönder