控制台输出"意外令牌{"在if(message.indexOf.("how are you")>=0){
行。
function send_message(message){
var prevState = $("#container").html();
if (prevState.length > 3){
prevState = prevState + "<br>";
}
$("#container").html(prevState + "<span class='current_msg'> + '<span class = 'bot'>Chatbot: </span>' + message</span>");
$(".current_msg").hide();
$(".current_msg").delay(slow).fadeIn();
$(".current_msg").removeClass("current_msg");
}
var="username";
function ai(message){
if (username.length<3){ /*checks to see if var is empty*/
username = message;
send_message("Nice to meet you " + username + ", how are you doing?");
}
if(message.indexOf.("how are you")>=0){ /*error here*/
send_message("me's good");
}
if(message.indexOf.("time")>=0){
var date = new Date();
var h = date.getHours();
var m = date.getMinutes();
send_message("time: " + h + ":" + m);
}
}
答案 0 :(得分:1)
在if(message.indexOf.("how are you")>=0){ /*error here*/
行上indexOf
后有一个额外的点。 if(message.indexOf.("time")>=0){
答案 1 :(得分:0)
你应该犯这样的错误:
if(message.indexOf("time") >= 0 ){
}