javascript switch

Solutions on MaxInterview for javascript switch by the best coders in the world

showing results for - "javascript switch"
Juan Diego
20 Oct 2017
1switch ($element) {
2    case 0:
3        echo "i es igual a 0";
4        break;
5    case 1:
6        echo "i es igual a 1";
7        break;
8    case 2:
9        echo "i es igual a 2";
10        break;
11}
Samuel
28 Feb 2016
1switch(expression) {
2  case x:
3    // code block
4    break;
5  case y:
6    // code block
7    break;
8  default:
9    // code block
10}
Alberto
06 Nov 2019
1switch (a) {
2    case 1:
3        alert('case 1 executed');
4        break;
5    case 2:
6        alert("case 2 executed");
7        break;
8   case 3:
9        alert("case 3 executed");
10        break;
11    case 4:
12        alert("case 4 executed");
13        break;
14    default:
15        alert("default case executed");
16}
Alena
28 Oct 2017
1//javascript multiple case switch statement
2var color = "yellow";
3var darkOrLight="";
4switch(color) {
5    case "yellow":case "pink":case "orange":
6        darkOrLight = "Light";
7        break;
8    case "blue":case "purple":case "brown":
9        darkOrLight = "Dark";
10        break;
11    default:
12        darkOrLight = "Unknown";
13}
14
15//darkOrLight="Light"
Deandre
20 Jan 2018
1let color = "black";
2
3switch(color){
4    case "red":
5        console.log("color is red");
6        break;
7    case "white":
8        console.log("color is white");
9        break;
10    case "black":
11        console.log("color is black");
12        break;
13    default:
14        console.log("unknow color");
15}
Amadou
23 Jun 2020
1var color = "yellow";
2var darkOrLight="";
3switch(color) {
4    case "yellow":case "pink":case "orange":
5        darkOrLight = "Light";
6        break;
7    case "blue":case "purple":case "brown":
8        darkOrLight = "Dark";
9        break;
10    default:
11        darkOrLight = "Unknown";
12}
similar questions
queries leading to this page
javascript switch