From 4b170d36eea644b8e7fb6912c0035ef0914d0299 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 22 Sep 2019 16:00:19 -0400 Subject: [PATCH 1/3] finished --- chatbot.js | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ index.html | 1 + 2 files changed, 56 insertions(+) create mode 100644 chatbot.js diff --git a/chatbot.js b/chatbot.js new file mode 100644 index 0000000..d1d9a07 --- /dev/null +++ b/chatbot.js @@ -0,0 +1,55 @@ + + + +let bot = [ + { input: "Hello", + output:["a" ,"ssb","ccccccc"] }, + { input: "what is your name", + output: ["a" ,"b","c"] }, + { input: "How old are you", + output:["a" ,"b","c"] }, + + ] + +/*Your reply function will now have the following: +Declare a variable called ‘question’ and assign to it the value of the HTML +element. HINT: you should already have this done from last week.*/ +let outputDom = document.getElementById("output"); + +function reply() { + var question = document.getElementById("input").value; + let randomNumber = Math.floor(Math.random()*3); + let filterType = null; + + filterType = bot.filter( item => + item.input == question + ); + + if(filterType.length > 0){ + let asnwers = filterType[0].output; + if(document.getElementById("shortest").checked==true){ + outputDom.innerHTML = asnwers.sort()[0]; + + }else if (document.getElementById("longest").checked==true){ + outputDom.innerHTML = asnwers.sort()[asnwers.length-1]; + + console.log("longest answer"); + }else{ + outputDom.innerHTML = asnwers[randomNumber]; + console.log("random answer"); + + } + } + + + + else { + document.getElementById('output').innerHTML = "I don't understand that command"; + + } +} + + +document.getElementById("submit").addEventListener('click', reply); + + \ No newline at end of file diff --git a/index.html b/index.html index c516c16..bd11558 100755 --- a/index.html +++ b/index.html @@ -2,6 +2,7 @@ My First Chatbot + From f922d51b54106a7fc8928642abf4c8a15a3111ed Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 22 Sep 2019 16:04:26 -0400 Subject: [PATCH 2/3] finished --- chatbot.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/chatbot.js b/chatbot.js index d1d9a07..d0ed0cd 100644 --- a/chatbot.js +++ b/chatbot.js @@ -3,11 +3,11 @@ let bot = [ { input: "Hello", - output:["a" ,"ssb","ccccccc"] }, + output:["Good morning" ,"Good evnning","Hello, how are you?"] }, { input: "what is your name", - output: ["a" ,"b","c"] }, + output: ["not sure" ,"nothing","chatbot"] }, { input: "How old are you", - output:["a" ,"b","c"] }, + output:["0" ,"very old","not sure"] }, ] From 383c4fff72c6d7901bec0989d561dd2dec5ddd32 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 29 Sep 2019 23:47:49 -0400 Subject: [PATCH 3/3] complete part3 --- chatbot.js | 71 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 43 insertions(+), 28 deletions(-) diff --git a/chatbot.js b/chatbot.js index d0ed0cd..ed3e57e 100644 --- a/chatbot.js +++ b/chatbot.js @@ -1,52 +1,67 @@ +let bot = [ + { + input: ["hello!", "how are you?", "how is the weather today?"], + output: ["Hi" ,"I am good","Fantastic?"] + }, + { + input: ["what is your name?", "how old are you?", "What is your major?"], + output: ["Riham", "very old", "astronaut"] + }, + { + input: ["where are you from?", "how many language do you speak?", "do you have pets?"], + output: [" From a planet called the earth", "four ", "no"] + }, +]; + -let bot = [ - { input: "Hello", - output:["Good morning" ,"Good evnning","Hello, how are you?"] }, - { input: "what is your name", - output: ["not sure" ,"nothing","chatbot"] }, - { input: "How old are you", - output:["0" ,"very old","not sure"] }, - - ] - -/*Your reply function will now have the following: -Declare a variable called ‘question’ and assign to it the value of the HTML -element. HINT: you should already have this done from last week.*/ let outputDom = document.getElementById("output"); function reply() { - var question = document.getElementById("input").value; + let question = document.getElementById("input").value.toLowerCase(); + console.log(question) let randomNumber = Math.floor(Math.random()*3); let filterType = null; - - filterType = bot.filter( item => - item.input == question + + filterType = bot.filter(element => + element.input.includes(question) ); + console.log(output); + + + + //filterType = bot.filter( item => + // item.input == question + // ); + + let asnwer = "" if(filterType.length > 0){ let asnwers = filterType[0].output; if(document.getElementById("shortest").checked==true){ - outputDom.innerHTML = asnwers.sort()[0]; + asnwer = asnwers.sort()[0]; + + - }else if (document.getElementById("longest").checked==true){ - outputDom.innerHTML = asnwers.sort()[asnwers.length-1]; - console.log("longest answer"); + }else if (document.getElementById("longest").checked==true){ + answer = asnwers.sort()[asnwers.length-1]; + }else{ - outputDom.innerHTML = asnwers[randomNumber]; - console.log("random answer"); + answer = asnwers[randomNumber]; + } } - - - - else { - document.getElementById('output').innerHTML = "I don't understand that command"; + + else { + //document.getElementById('output').innerHTML += `bot` + ` : ` + ``+ `I don't understand that command` + `\n` + `User` + ` : ` + `` + question; + answer="I do not understand"; } + + outputDom.innerHTML += `user: ${question}\nbot ${answer}\n` }