title: indexOf within Switch
body: <p>I have a Javascript-based bot for a Xat chatroom which also acts as an AI. I've recently decided to redo the AI part of it due to it becoming an absolutely massive chain of <code>else if</code> statements, becoming nearly impossible to work with.</p>
  
  <p>I did some research and came up with a new idea of how to handle responses. I'll give you the code segment first:</p>
  
  <pre><code>function msgSwitch(id,msgRes) {
  var botResponse = [];
  
  switch (msgRes) {
    case (msgRes.indexOf("hi") !=-1):
      botResponse.push("HELLO. ");
    case (msgRes.indexOf("how are you") !=-1):
      botResponse.push("I AM FINE. ")
    case (msgRes.indexOf("do you like pie") !=-1):
      botResponse.push("I CAN'T EAT. THANKS, ASSHAT. ")
    default:
      respond (botResponse);
      spamCount(id);
      break;
  }
  
  }
  </code></pre>
  
  <p>The idea here is to check <code>msgRes</code> (the user's input) and see how many cases it matches. Then for each match, it'll <code>push</code> the response into the <code>botResponse</code> array, then at the end, it'll reply with all the messages in that array.</p>
  
  <p><strong>Example</strong></p>
  
  <p>User Msg: <code>Hi! How are you?</code></p>
  
  <p>msgRes: <code>hi how are you</code></p>
  
  <p><strong>Bot Matches:</strong></p>
  
  <p><code>hi</code> > pushes <code>HELLO.</code> to array</p>
  
  <p><code>how are you</code> > pushes <code>I AM FINE.</code> to array</p>
  
  <p><strong>Bot Responds:</strong> <code>HELLO. I AM FINE.</code></p>
  
  <p>This in turn saves me the trouble of having to write an <code>if</code> for each possible combination.</p>
  
  <p>However, after looking into it some more, I'm not sure if it's possible use <code>indexOf</code> inside  of a switch. Does anyone know of a way around this or have a better idea for handling responses in the same manner?</p>
  
  <p>EDIT:</p>
  
  <p><strong>To Avoid the XY Problem (To clarify my problem)</strong></p>
  
  <p>I need a clean alternative to using a massive chain of <code>else if</code> statements. There are going to be hundreds of word segments that the bot will respond to. Without the ability for it to keep searching for matches, I'd have to write a new <code>else if</code> <strong>for every combination</strong>.</p>
  
  <p>I'm hoping for a way to have it scan through every statement for a match, then combine the response for each match together into a single string.</p>
  
  <p>EDIT 2:
  I should also add that this is being ran on Tampermonkey and not a website.</p>