-
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
Conversation
|
Good job structuring your code! Click here for the answerThat has to do with how you're loading the script - the position of where you include the Like this: <script src="script/script.js" defer></script>Now your chatbot produces output! |
| // Reply function for getting input element | ||
| function reply(){ | ||
| const question = document.querySelector("#input"); | ||
| if(question.value === "hello"){ |
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.value with the string "hello", you should compare question.value with the input of your object, ioChatbot.
| function reply(){ | ||
| const question = document.querySelector("#input"); | ||
| if(question.value === "hello"){ | ||
| document.querySelector("#output").textContent = "hi"; |
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.
You should update this value with the output of ioChatbot
| } | ||
|
|
||
| if(document.querySelector("#submit")){ | ||
| document.querySelector("#submit").addEventListener("click", function(){ |
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.
For your callback function, it's not necessary to create an anonymous function (a function with no name, i.e. function() { ... }) and call reply() inside of it. It works, but you can just pass in the name of your reply function directly. Like this:
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 reply function because you have included it inline:
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.";
}
});
mmmm