switch statements injavascript code example
Example 1: switch case in javascript
function whatToDrink(time){
var drink ;
switch (time) {
case "morning":
drink = "Tea";
break;
case "evening":
drink = "Shake";
break;
default:
drink="Water";
}
return drink;
}
console.log(whatToDrink("morning"))
console.log(whatToDrink("evening"))
console.log(whatToDrink("night"))
console.log(whatToDrink("daytime"))
Example 2: switch case in js
var coll1="kjc;
switch(coll1)
{
case "kjc":
alert("youre special");
break;
case "horizon":
alert("worst behaviour");
break;
case "cmr" :
alert("worst character");
break;
default:
alert("kjc is best");
break;
}