Skip to content

Conversation

@hamzakoc
Copy link

No description provided.

@epq
Copy link
Collaborator

epq commented Sep 23, 2019

Very good work!
Good job including several different inputs and outputs. Also good job converting the user's input to lowercase to handle different capitalization.

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

let question = document.getElementById("input").value.toLowerCase();

//conditional statement
if (chatbot.input[0] === question) {
Copy link
Collaborator

Choose a reason for hiding this comment

The 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?
For example, if I had 20 possible input/outputs, that would be a lot of if statements to write!

Click here for a suggestion
  • You could loop through the chatbot's input and compare that with the user's input to check if it's valid. If there is a match, display it. Otherwise display "enter a valid value."

  • Or you could use the array indexOf() method to see if the user's input is valid. If it is, display it. Otherwise, display "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()}) No newline at end of file
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.";
   }
});

@@ -0,0 +1,33 @@

//properties added to the object: ‘input’ and ‘output’ as an array
Copy link
Collaborator

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!

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