【发布时间】:2017-04-15 06:36:39
【问题描述】:
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 语句运行,我有一个包含不同字符串的数组,如果消息包含来自该数组的字符串,则运行案例。但是什么都没有发生,一切似乎都正确,这里可能有什么问题?
【问题讨论】:
-
仔细阅读
switch的文档。
标签: javascript node.js string switch-statement