Friday, 14 April 2017

Switch statement not working when using .includes()

client.on('chat', function(channel, userstate, message, self){



  switch(message){
    case message.includes(emotes[0]):
      numberOfEmotes[0]++;
      console.log("Emote0 has been used " + numberOfEmotes[0] + " time(s)");
      break;
    case message.includes(emotes[1]):
      numberOfEmotes[1]++;
      console.log("Emote1 has been used " + numberOfEmotes[1] + " time(s)");
      break;
    case message.includes(emotes[2]):
      numberOfEmotes[2]++;
      console.log("Emote2 has been used " + numberOfEmotes[2] + " time(s)");
      break;
    case message.includes(emotes[3]):
      numberOfEmotes[3]++;
      console.log("Emote3 has been used " + numberOfEmotes[3] + " time(s)");
      break;
  }

/*  if(message.includes(emotes[0])){
    numberOfEmotes[0]++;
    console.log("Emote0 has been used " + numberOfEmotes[0] + " time(s)");
  }*/


  //console.log("** " + message + " **");
});

When the function chat.on is called a variable of message with a string is supposed to run through the switch statement, I have an array with different strings and if the message includes a string from that array, run the case. But nothing happens, it all seems right what could be wrong here?



via Hooga

No comments:

Post a Comment