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