-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.js
29 lines (22 loc) · 1.15 KB
/
bot.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
function answerQuery(query) {
query = query.toLowerCase();
if (query.indexOf("rain") != -1 || query.indexOf("sun") != -1 || query.indexOf("weather") != -1){
return "I do not care too much about weather, I'm locked inside a data center.";
else if (query.indexOf("tea") != -1 || query.indexOf("biscuits") != -1)
return "Now, I can talk about tea and biscuits as well";
} else if (query.indexOf("football") != -1 ){
return "My favourite team is PSG"
}
return "Sorry Dave, I cannot do that."
}
function handleSayClick() {
// We first get the 'message' that the user entered and 'conversation' element
// which we are using for showing all the conversation history
var message = document.getElementById('message').value.toLowerCase();
var conversation = document.getElementById('conversation');
// Get answer for the given query and show the query & answer
var answer = answerQuery(message)
conversation.innerHTML += "<p><strong>You:</strong> " + message + "</p>";
conversation.innerHTML += "<p><strong>Useless bot:</strong> " + answer + "</p>";
}
document.getElementById("sayit").onclick = handleSayClick;