-
Notifications
You must be signed in to change notification settings - Fork 10
week8 homework submission #7
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: Hamza-Koc
Are you sure you want to change the base?
Changes from all commits
2b9d08e
4958f72
a86bb43
9d5748a
b99c7f6
56fb36c
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 @@ | ||
| theme: jekyll-theme-slate |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
|
|
||
| //properties added to the object: ‘input’ and ‘output’ as an array | ||
|
|
||
| var chatbot = { | ||
| input: ["hello", "how are you", "how is your day", "what do you do"], | ||
| output: [ "hi", "greaatt!", "good", "software developer" ] | ||
| }; | ||
|
|
||
| //print variable | ||
| //console.log(chatbot); | ||
|
|
||
| //created a function called ‘reply’. | ||
| function reply() { | ||
| let question = document.getElementById("input").value.toLowerCase(); | ||
|
|
||
| //conditional statement | ||
| if (chatbot.input[0] === question) { | ||
|
Collaborator
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. Can you think of checking for the input in a different way without all of these if and else if statements? Click here for a suggestion
|
||
| document.getElementById("output").value = chatbot.output[0] | ||
| } else if (chatbot.input[1] === question) { | ||
| document.getElementById("output").value = chatbot.output[1] | ||
| }else if (chatbot.input[2] === question) { | ||
| document.getElementById("output").value = chatbot.output[2] | ||
| }else if (chatbot.input[3] === question) { | ||
| document.getElementById("output").value = chatbot.output[3] | ||
| } else { | ||
| document.getElementById("output").value = "Enter a valid value" | ||
| } | ||
|
|
||
| } | ||
|
|
||
|
|
||
| //attach a 'click' event listener to the <button> element defined in the HTML file. | ||
| document.getElementById("submit").addEventListener("click", function() {reply()}) | ||
|
Collaborator
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. For your callback function, it's not necessary to create an anonymous function (a function with no name, i.e. document.querySelector("#submit").addEventListener("click", reply);Or your callback function can be an anonymous function like below. If you do this, you don't need to write a separate document.querySelector("#submit").addEventListener("click", function() {
const question = document.querySelector("#input");
if(question.value === "hello"){
document.querySelector("#output").textContent = "hi";
} else{
document.querySelector("#output").textContent = "I don't understand that command. Please enter another.";
}
}); |
||
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.
Nice job adding comments throughout this file!