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.
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.
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.
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