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 + " **");
});
当函数chat.on被称为消息的变量用字符串应该通过开关语句来运行,我有不同的字符串,并且如果阵列消息包含该数组中的一个字符串,运行该案例。但没有任何反应,这一切似乎正确,这可能是错误的?switch语句
文档阅读'之开关更加紧密。 – 2017-04-15 07:38:13