Skip to content

Conversation

@kursadc
Copy link

@kursadc kursadc commented Sep 15, 2019

No description provided.

@epq
Copy link
Collaborator

epq commented Sep 21, 2019

Works well, good job!
A suggestion for extending your chatbot - how about handling the case if the user enters in an input that's capitalized differently, e.g. "how are you" instead of "How are you"?

You can also organize your code into different folders to keep CSS, and JavaScript in different folders, see this link for more information.


}

document.getElementById("submit").addEventListener("click", function() {reply()})
Copy link
Collaborator

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.";
   }
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants