-
Notifications
You must be signed in to change notification settings - Fork 10
hw8 #4
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: Yunus-Unsal
Are you sure you want to change the base?
hw8 #4
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,24 @@ | ||
| // Declare input and output | ||
| const ioChatbot = { | ||
| input : "hello", | ||
| output : "hi" | ||
| }; | ||
| console.log(ioChatbot); | ||
|
|
||
| // Reply function for getting input element | ||
| function reply(){ | ||
| const question = document.querySelector("#input"); | ||
| if(question.value === "hello"){ | ||
| document.querySelector("#output").textContent = "hi"; | ||
|
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. You should update this value with the |
||
| } else{ | ||
| document.querySelector("#output").textContent = "I don't understand that command. Please enter another."; | ||
| } | ||
|
|
||
| console.log(question.value); | ||
| } | ||
|
|
||
| if(document.querySelector("#submit")){ | ||
| document.querySelector("#submit").addEventListener("click", function(){ | ||
|
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.";
}
}); |
||
| reply(); | ||
| }); | ||
| } | ||
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.
Instead of comparing
question.valuewith the string"hello", you should comparequestion.valuewith theinputof your object,ioChatbot.