-
Notifications
You must be signed in to change notification settings - Fork 0
/
chatbot.html
36 lines (36 loc) · 1.4 KB
/
chatbot.html
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
30
31
32
33
34
35
36
<html>
<style>
#btnSubmit {
background-color: #0C00FF;
padding: 12px 28px;
border-radius: 8px;
}
</style>
<!--Create text box for player to type in-->
<input type="text" id="message">
<!--Create paragraph to show chatbot's messages-->
<p id="chatbotText"></p>
<!--Create button to send messages to chatbot-->
<button id="btnSubmit">Send</button>
<script>
//function to process user messages
var button = document.getElementById("btnSubmit")
var hasBotAskedHowPlayerIs = false;
button.onclick = function() {
var message = document.getElementById("message").value;
message.toLowerCase();
//create array with list of phrases to use in response to "Hello"
var helloMessages = ["Hello.", "Hi.", "Hello!", "Hi!", "Hello. How are you doing?", "Hi. How are you?"];
//function to pick random phrase
function randomWord(arr) {
return arr[Math.floor(Math.random() * arr.length)];
}
if (message === "hi" || message === "hello" || message === "hi!" || message === "hello!" || message === "hi." || message === "hello." || message === "hey." || message === "hey" || message === "hey!") {
var helloMessage = document.getElementById('chatbotText').innerHTML = randomWord(helloMessages);
if(helloMessage === "Hello. How are you doing?" || helloMessage === "Hi. How are you?") {
hasBotAskedHowPlayerIs = true;
}
} else if(message === "good" || message === "good!" || message === "good." || message === "")
}
</script>
</html>