Replacing If Else Chains with Switch code example
Example: Replacing If Else Chains with Switch
function chainToSwitch(val) {
var answer = "";
switch(val){
case "bob":
answer = "Marley";
break;
case 42:
answer = "The Answer";
break;
case 1:
answer = "There is no #1";
break;
case 99:
answer = "Missed me by this much!";
break;
case "John":
answer = "";
break;
case 156:
answer = "";
break;
default:
answer = "Ate Nine";
}
return answer;
}
chainToSwitch(7);