Skip to content

Conversation

@HomamS
Copy link

@HomamS HomamS commented Sep 15, 2019

Done!

@epq
Copy link
Collaborator

epq commented Sep 23, 2019

Good job, your chatbot works well!
Good job including different inputs and outputs. A suggestion is that you could handle different cases for capitalization, e.g. the user could type in "Hello", "hello" or "HELLO" and those would all be valid responses.

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

};
console.log(object);
//here we define function called reply and this function will let the chatpot to give me the proper anwers based on the input the we give
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.

We haven't talked about it so much in class, but generally it helps to improve readability in your code if you follow these rules for adding whitespace: see here. You should be able to format your code with your code editor so you don't have to add the spacing manually.

For example, here's your reply function with spacing added:

  function reply() {
    //I defince variable called question and I put inside this variable the value (input from user)
    let question = document.getElementById('input').value;
    //I used if statement to check the input and give the outpot
    if (object.input.includes(question)) {
      //here we define variable called i, inside this variable i checked the index of the input based on the location in array
      let i = object.input.indexOf(question);
      //last step is to give the output location based on the input location in the array
      document.getElementById('output').textContent = object.output[i];

    } else {
      document.getElementById('output').textContent = "I don't understand that command. Please enter another";

    }
  }

//I defince variable called question and I put inside this variable the value (input from user)
let question = document.getElementById('input').value;
//I used if statement to check the input and give the outpot
if(object.input.includes(question)){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You've written a good check for valid input. You can also only use the indexOf method instead of using both includes and indexOf. indexOf returns -1 if the value is not found in the array so you can use this to check if the input is valid and get the index of the input.

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