Answers for "Switch Case Statement in JavaScript"

155

js switch case

switch(expression) {
  case x:
    // code block
    break;
  case y:
    // code block
    break;
  default:
    // code block
}
Posted by: Guest on February-21-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
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 Statement in JavaScript

var a=3;
switch(a)
{
    case 1:
        console.log("Value of a is 1");
        break;
 
    case 2: // grouped three cases
    case 3:
    case 4:
        console.log("Value of between 2 and 4");
        break;
 
    default:
        console.log("Value of a not matched");
        break;
}
 
// Output: Value of between 2 and 4
Posted by: Guest on September-02-2021
0

Switch Case Statement in JavaScript

var day = new Date();
switch(day.getDay()) 
   {
    case 0:
        console.log("Today is Sunday");
        break;
    case 1:
        console.log("Today is Monday");
        break;
 
    case 2:
        console.log("Today is Tuesday");
        break;
 
    case 3:
        console.log("Today is Wednesday");
        break;
 
    case 4:
        console.log("Today is Thursday");
        break;
 
    case 5:
        console.log("Today is Friday");
        break;
 
    case 6:
        console.log("Today is Saturday");
        break;
 
    default:
        console.log("No Information Found");
        break;
 }
 
// Output : Today is Monday
Posted by: Guest on September-02-2021
0

Switch Case Statement in JavaScript

switch(x){
    case value1: // if x === value1 
     ...      
        break;
    case value2: // if x === value2
        ...
        break;   
    default: // if x not match 
        ...
}
Posted by: Guest on September-02-2021

Code answers related to "Switch Case Statement in JavaScript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language