From c198b7d7b2ac0aa707521583dea0a5aaad7cd7b3 Mon Sep 17 00:00:00 2001 From: terratamo Date: Sun, 22 Sep 2019 18:01:40 -0400 Subject: [PATCH 1/2] hm9 --- index.html | 1 + script.js | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 script.js diff --git a/index.html b/index.html index c516c16..84a639b 100755 --- a/index.html +++ b/index.html @@ -2,6 +2,7 @@ My First Chatbot + diff --git a/script.js b/script.js new file mode 100644 index 0000000..7b9a001 --- /dev/null +++ b/script.js @@ -0,0 +1,65 @@ +const ioChatbot = [ { + input : "hello", + output : ["Hello", "Hi", "Greetings"] + }, + { + input : "What is your favorite color?", + output : ["i am not sure", "There are too many", "i like everyone",] + }, + { + input : "How are you", + output : ["fine", "great", "not so good"] + } + +] + + + +console.log(ioChatbot); + +function reply() { + + let question = document.getElementById("input").value.tolowerCase(); + + let randomNumber = Math.floor (Math.random()*3) + + let be = document.getElementById("output").value + + let filterType = null + + let response = ioChatbot.filter(item => {return item.input === question } ) + + if (response.length>1){ + + if (document.getElementById("longest").checked == true ){ + + be= response[0].output[2]; + + } else if (document.getElementById("shortest").checked == true ){ + + be = response[0].output[0]; + + } else { + + be = response[0].output[randomNumber]; + } + + + }else { + + be = "i do not understand that comment. Please enter another!" + + } + + + + + + +} + +//document.getElementById("submit").addEventListener("click",function() {reply()}); + +document.querySelector("#submit").addEventListener("click", function(){ + reply(); + }); \ No newline at end of file From 0b62c0ea8c8c1cc3025431cec3583a7a567bf193 Mon Sep 17 00:00:00 2001 From: terratamo Date: Tue, 1 Oct 2019 17:34:41 -0400 Subject: [PATCH 2/2] ioChatbot3 --- index.html | 10 +++---- script.js | 88 +++++++++++++++++++++++++----------------------------- 2 files changed, 45 insertions(+), 53 deletions(-) diff --git a/index.html b/index.html index 84a639b..2bdd135 100755 --- a/index.html +++ b/index.html @@ -1,14 +1,14 @@ - My First Chatbot - - + My First ioChatbot + +
-

My first chatbot!

+

My first ioChatbot!

Talk to your bot!

@@ -23,7 +23,7 @@

Talk to your bot!


Chat history

-
+

diff --git a/script.js b/script.js index 7b9a001..ea583ba 100644 --- a/script.js +++ b/script.js @@ -1,65 +1,57 @@ -const ioChatbot = [ { - input : "hello", - output : ["Hello", "Hi", "Greetings"] - }, - { - input : "What is your favorite color?", - output : ["i am not sure", "There are too many", "i like everyone",] - }, - { - input : "How are you", - output : ["fine", "great", "not so good"] - } - -] - +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); +console.log(ioChatbot) +//for function function reply() { - let question = document.getElementById("input").value.tolowerCase(); - - let randomNumber = Math.floor (Math.random()*3) - - let be = document.getElementById("output").value - - let filterType = null - - let response = ioChatbot.filter(item => {return item.input === question } ) - - if (response.length>1){ - - if (document.getElementById("longest").checked == true ){ + let question = document.getElementById("input").value.toLowerCase(); - be= response[0].output[2]; - } else if (document.getElementById("shortest").checked == true ){ - be = response[0].output[0]; + const response = ioChatbot.filter( item => item.input.includes(question)) - } else { - - be = response[0].output[randomNumber]; - } +// for value 0 to 2 + let randomNumber = Math.floor(Math.random()*3); + +// for longest , shortest , random responses + if(response.length>0){ - }else { + if(document.getElementById('shortest').checked === true){ - be = "i do not understand that comment. Please enter another!" + 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()}); - -document.querySelector("#submit").addEventListener("click", function(){ - reply(); - }); \ No newline at end of file +document.getElementById("submit").addEventListener("click", function() {reply()});