From 606cd343c2da45d8b971613bd1c277ddcefc0df9 Mon Sep 17 00:00:00 2001 From: aalitenaye Date: Mon, 7 Oct 2019 21:12:42 -0400 Subject: [PATCH 1/3] chatbot 4 --- README.md | 4 +++ chatbot1-2-3-4.js | 69 +++++++++++++++++++++++++++++++++++++++++++++++ index.html | 17 ++++++++---- style.css | 49 +++++++++++++++++++++++++++++++++ 4 files changed, 134 insertions(+), 5 deletions(-) create mode 100644 chatbot1-2-3-4.js create mode 100644 style.css diff --git a/README.md b/README.md index 4f0080f..0cad391 100644 --- a/README.md +++ b/README.md @@ -6,3 +6,7 @@ Please see the instructions [here](https://docs.google.com/document/d/1BP27Tjgit # Chatbot - week 10 Please see the instructions [here](https://docs.google.com/document/d/1qrdVIXy7D10M3AkQUIKV0z7kkIOoCsofMD3ZJexyy2s/edit?usp=sharing) + +# Chatbot - week 11 + +Please see the instructions [here](https://docs.google.com/document/d/1sWx_g90eLzSyfLRNfeZzCYUGqR5ArW4LT10D2dWctCU/edit?usp=sharing) diff --git a/chatbot1-2-3-4.js b/chatbot1-2-3-4.js new file mode 100644 index 0000000..8f5d05a --- /dev/null +++ b/chatbot1-2-3-4.js @@ -0,0 +1,69 @@ +let chatbot1 = [ + { + input: ['Hello'], + output: ['Hi', 'Salam', 'Hey'] + }, + { + input: ['How are you?'], + output: ['Great!', 'It is been going great.', 'I am awesome.'] + }, + { + input: ['How many languages can you speak?'], + output: ['I can only speak one.', 'I can speak 2.', 'I am bilingual.'] + } +]; + +console.log(chatbot1); + +function reply() { + let question = document.querySelector('#input').value.toLowerCase(); + let randomNumber = Math.floor((Math.random() * 3)); + let filterType = null; + let textarea = document.getElementById("output"); + const output = chatbot1.filter(item => item.input.includes(question)); + if (question === chatbot1.input) { + textarea.innerHTML = chatbot1.output; + } + if (output.length > 0) { + if (document.getElementById('longest').checked) { + longOp = output[0].output.sort((a, b) => b.length - a.length); + appendToOutput(longOp[0], 1); + }else if (document.getElementById('shortest').checked){ + shortOp = output[0].output.sort((a, b) => a.length - b.length); + appendToOutput(shortOp[0], 1); + } else { + appendToOutput(output[0].output[randomNumber], 1); + } + } + else { + appendToOutput('I do not understand that command. Please enter another.'); + } + } +reply(); + +var listener = document.querySelector('#submit'); +listener.addEventListener('click', function(e) { + e.preventDefault(); + reply(); + document.querySelector('#submit').reset(); +}) // assigning to it AN addEventListener. +//============================================================================== +//CHATBOT FOUR +function showDog() { + const xmlHttp = new XMLHttpRequest(); + xmlHttp.onreadystatechange = function () { + if (xmlHttp.readyState == 4) { + let url = JSON.parse(xmlHttp.responseText).message; + document.querySelector('#show-content img').setAttribute('src', url) + document.getElementById('show-content').classList.remove('hide'); + } + } + xmlHttp.open('GET', 'https://dog.ceo/api/breeds/image/random', true); + xmlHttp.send(); +} + +function delayedAlert() { + setTimeout(function() { + alert("Did you forget about me? it's your friend, the Alarm!") + }, 2000); +} diff --git a/index.html b/index.html index c516c16..d64fc92 100755 --- a/index.html +++ b/index.html @@ -1,15 +1,22 @@ My First Chatbot - + + +
+
+ +
+ +

My first chatbot!

Talk to your bot!

- +
@@ -18,16 +25,16 @@

Talk to your bot!

Shortest Answer Longest Answer
- +

Chat history


-
+
- \ No newline at end of file + diff --git a/style.css b/style.css new file mode 100644 index 0000000..e4c4646 --- /dev/null +++ b/style.css @@ -0,0 +1,49 @@ + From 995bd45e6d01744ec91b837a5210eb810831adbf Mon Sep 17 00:00:00 2001 From: aalitenaye Date: Tue, 15 Oct 2019 13:56:06 -0400 Subject: [PATCH 2/3] Chatbot 5 --- chatbot1-2-3-4.js => chatbot1-2-3-4-5.js | 20 +++++++++ chatbot_style.css | 53 ------------------------ 2 files changed, 20 insertions(+), 53 deletions(-) rename chatbot1-2-3-4.js => chatbot1-2-3-4-5.js (72%) delete mode 100755 chatbot_style.css diff --git a/chatbot1-2-3-4.js b/chatbot1-2-3-4-5.js similarity index 72% rename from chatbot1-2-3-4.js rename to chatbot1-2-3-4-5.js index 8f5d05a..5539357 100644 --- a/chatbot1-2-3-4.js +++ b/chatbot1-2-3-4-5.js @@ -67,3 +67,23 @@ function delayedAlert() { alert("Did you forget about me? it's your friend, the Alarm!") }, 2000); } +//============================================================================= +//CHATBOT 5 +// Use async/await to write a function to call the Weather API +//and parse the API upon a request for the weather if the user inputs “Show me the weather” +async function callWeather() { + const executeFirst = await requestWeather(); +} + +var requestWeather = new XMLHttpRequest() + requestWeather.open('GET', 'https://openweathermap.org/api', 'api.openweathermap.org/data/2.5/forecast?id=524901&APPID=ded48b63426832eb7e0f825530b65a61', true) + requestWeather.onload = function() { + var = promise = new Promise(function(resolve, reject) { + setTimeout(function() { + if (chatbot1.input[] = 'Show me the weather') {resolve(requestWeather); return + } + reject('Error') + }) + }, 200) +} +requestWeather.send(); diff --git a/chatbot_style.css b/chatbot_style.css deleted file mode 100755 index a915556..0000000 --- a/chatbot_style.css +++ /dev/null @@ -1,53 +0,0 @@ -button { - font-family: Helvetica; - font-size: 10pt; - /*width: 92px;*/ -} - -textarea { - font-family: arial; - font-size: 10pt; -} - -body { - color: #333; - background-color: #efefef; - font: 13px helvetica, arial, freesans, clean, sans-serif; -} - -#demo { - width: 80%; - max-width: 1000px; - margin-left: auto; - margin-right: auto; - padding: 20px; - - background-color: #F8F8F8; - border: 1px solid #ccc; - box-shadow: 0 0 10px #999; - line-height: 1.4em; - font: 13px helvetica, arial, freesans, clean, sans-serif; - color: black; -} - -#demo #input { - padding: 8px; - font-size: 14px; - border: 1px solid #ddd; - width: 400px; -} - -#demo textarea { - padding: 8px; - font-size: 14px; - border: 1px solid #ddd; - width: 800px; -} - -input:focus { - outline: none; -} - -textarea:focus { - outline: none; -} \ No newline at end of file From 309c676ee189dbc3d0a06a50113c98a1888fa887 Mon Sep 17 00:00:00 2001 From: aalitenaye Date: Wed, 16 Oct 2019 19:41:29 -0400 Subject: [PATCH 3/3] rename chatbot.js --- chatbot1-2-3-4-5.js => chatbot.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename chatbot1-2-3-4-5.js => chatbot.js (100%) diff --git a/chatbot1-2-3-4-5.js b/chatbot.js similarity index 100% rename from chatbot1-2-3-4-5.js rename to chatbot.js