I want to process several values in one, but it doesn't work well because I wrote in the case. What should I do?
function daysInMonth( month ){
switch(month){
case 2:
return 28;
break;
case 4,6,9,11:
return 30;
default:
return 31; }
}
console.log(daysInMonth(9));
//=> 31
To process multiple values at once in a switch statement in javascript, you must write down the case several times as shown below.
function daysInMonth( month ){
switch(month){
case 2:
return 28;
case 4:
case 6:
case 9:
case 11:
return 30;
default:
return 31; }
}
console.log(daysInMonth(9));
// // => 30
I don't know the intention to process multiple values at once in the switch statement.
In this case, it seems better to treat it as an if statement.
As far as I know, the switch case is used for processing by case.
541 Unable to install versioned in Google Colab
529 Uncaught (inpromise) Error on Electron: An object could not be cloned
546 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
547 PHP ssh2_scp_send fails to send files as intended
547 Who developed the "avformat-59.dll" that comes with FFmpeg?
© 2024 OneMinuteCode. All rights reserved.