Is it possible to do that? For exanple for 'a' or 'b' is equal to 'X'. If 'c' or 'd' or 'e' is equal to 'Y'
var qwerty = function() {
var month = 'a';
var cases = {
'a' || 'b' : month = 'X',
'c' || 'd' || 'e' : month = 'Y'
};
if (cases[month]) {
cases[month]();
}
return month;
};
console.log( qwerty() );
Thank you in advance :)
There is no 'or' in a switch statement, as such. But you can stack up your cases like so:
switch(month){
case 'a':
case 'b':
month = 'X';
break;
case 'c':
case 'd':
case 'e':
month = 'Y';
break;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With