[removed] How can I simplify an if-statement with multiple OR conditions?

前端 未结 6 958
半阙折子戏
半阙折子戏 2021-01-16 17:22

Sorry if I\'ve made mistakes writing this post. I\'m new here and I don\'t know how this works, hope I learn quick. I am also new at JavaScript.

So the question is:

6条回答
  •  执笔经年
    2021-01-16 17:45

    The way you are implementing this logic I would suggest a switch statement for readability like such:

    switch (codePrompt){
    case "switch()": 
    {
        //Handle case
        break;
    }
    case "switch(background)": 
    {  
       //Handle Case
       break;
    }
    case "blur()":
    {
        //Handle Case
        break;
    }
    default :
    {
      alert("Wrong command, try again.");
      console.log("Wrong command, try again.");
    }
    

提交回复
热议问题