diff --git a/index.html b/index.html index c516c16..2bdd135 100755 --- a/index.html +++ b/index.html @@ -1,13 +1,14 @@ - My First Chatbot - + My First ioChatbot + +
-

My first chatbot!

+

My first ioChatbot!

Talk to your bot!

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

Talk to your bot!


Chat history

-
+

diff --git a/script.js b/script.js new file mode 100644 index 0000000..ea583ba --- /dev/null +++ b/script.js @@ -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()});