-
Notifications
You must be signed in to change notification settings - Fork 12
Iochatbotweek11 #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Iochatbotweek11 #24
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| 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 if( question === "show me a dog" ) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. might want to move this logic up so that your program doesn't have to go through all the logic above in this scenario |
||
| dogpictures(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. always camel case your names |
||
|
|
||
|
|
||
| } else if(question==='set an alarm') { | ||
| delayedAlert(); | ||
|
|
||
| } else { | ||
| document.getElementById("output").value="I do not understand that comment. Please enter another." | ||
| } | ||
| } | ||
|
|
||
| document.getElementById("submit").addEventListener("click", function() {reply()}); | ||
|
|
||
|
|
||
|
|
||
| function dogpictures(){ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. camelcase for consistency i.e. dogPictures |
||
|
|
||
| let image = new XMLHttpRequest(); | ||
|
|
||
| image.onreadystatechange=function(){ | ||
| if(image.readyState===4){ | ||
| let url= JSON.parse(image.responseText).message; | ||
|
|
||
| document.getElementById("dog").setAttribute('src', url); | ||
| } | ||
|
|
||
| } | ||
| image.open("GET", "https://dog.ceo/api/breeds/image/random"); | ||
| image.send(); | ||
|
|
||
| } | ||
|
|
||
|
|
||
|
|
||
| function delayedAlert(){ | ||
|
|
||
| setTimeout(function(){ | ||
| alert("Did you forget about me? it's your friend, the Alarm!") | ||
| }, 2000); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
always remove your console logs before you push