0
0

【jQuery】【JavaScript】switch文のメリット※フォールスルーを活用

Last updated at Posted at 2024-08-02

フォールスルーを活用方法を理解する必要がある

コード 19行

switch (Number(lamp)) {
    case 1: return;
    case 6:
        derby_king       = "-";
        doguti_sp        = "-";
        aiti_giant       = "-";
    case 5:
        tukemai_kosya    = "-";
        koiten           = "-";
        ipan_oni         = "-";
    case 4:
        kanto_gamashi    = "-";
        teikai_hiroin    = "-";
    default:
        kakedasi         = "-";     
        atozaki          = "-";     
        saikyo_b2        = "-";
}

元のコード 20行

if(Number(lamp) === 1) return;
if((Number(lamp) < 4)){ 
    kakedasi         = "-";     
    atozaki          = "-";     
    saikyo_b2        = "-";
}
if((Number(lamp) < 5)){ 
    kanto_gamashi    = "-";
    teikai_hiroin    = "-";
}
if((Number(lamp) < 6)){ 
    tukemai_kosya    = "-";
    koiten           = "-";
    ipan_oni         = "-";
}
if((Number(lamp) === 6)){
    derby_king       = "-";
    doguti_sp        = "-";
    aiti_giant       = "-";
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0