Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<!DOCTYPE HTML>
<head>
<title>My First Chatbot</title>
<link rel="stylesheet" type="text/css" href="chatbot_style.css">
<title>My First ioChatbot</title>
<link rel="stylesheet" type="text/css" href="ioChatbot_style.css">
<script type="text/javascript" src="script.js" defer></script>
</head>

<body>
<div id="demo">

<h1> My first chatbot! </h1>
<h1> My first ioChatbot! </h1>
<h3> Talk to your bot!</h3>

<div id="user">
Expand All @@ -22,7 +23,7 @@ <h3> Talk to your bot!</h3>
<br />

<h3> Chat history </h3>
<div id="chatBot">
<div id="ioChatbot">
<textarea id="output" name="ChatHistory" rows="15"></textarea>
<br />
</div>
Expand Down
57 changes: 57 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
const ioChatbot= [
{
input: ['hello', 'hi', 'greetings'],
output: ['Hello', 'Hey', 'Greetings']
},
{
input: ['what is your favourite colour?', 'who is your favourite HYF instructor?', 'who is your role model?'],
output: ['I am not sure.','There are too many to choose from', 'I like every one']
},

{
input: ['how are you?', 'how is the weather today?', 'how is Canada doing in the Olympics?'],
output: ['Fine', 'Great', 'Not so good']
},

];


console.log(ioChatbot)

//for function
function reply() {

let question = document.getElementById("input").value.toLowerCase();



const response = ioChatbot.filter( item => item.input.includes(question))

// for value 0 to 2
let randomNumber = Math.floor(Math.random()*3);


// for longest , shortest , random responses
if(response.length>0){

if(document.getElementById('shortest').checked === true){

document.getElementById("output").value +="you : "+question+ '\n' + "computer : "+ response[0].output.sort((a, b) => a.length - b.length)[0]+ '\n' +'\n';

}else if (document.getElementById('longest').checked === true){


document.getElementById("output").value +="you : "+question+ '\n'+"computer : "+response[0].output.sort((a, b) => b.length - a.length)[response.length-1]+ '\n' +'\n';

}else {


document.getElementById("output").value +="you : "+question+ '\n' +"computer : "+ response[0].output.sort((a, b) => b.length - a.length)[randomNumber]+ '\n' + '\n';
}

}else{
document.getElementById("output").value="I do not understand that comment. Please enter another."
}
}

document.getElementById("submit").addEventListener("click", function() {reply()});